@@ -391,7 +391,7 @@ public boolean uploadCertificateToHosts(String certificateCer, String alias, Str
391391 String certificatePem = getPretifiedCertificate (certificateCer );
392392 certificateSanity (certificatePem );
393393
394- DirectDownloadCertificateVO certificateVO = directDownloadCertificateDao .findByAlias (alias );
394+ DirectDownloadCertificateVO certificateVO = directDownloadCertificateDao .findByAlias (alias , hypervisorType , zoneId );
395395 if (certificateVO != null ) {
396396 throw new CloudRuntimeException ("Certificate alias " + alias + " has been already created" );
397397 }
@@ -453,15 +453,22 @@ public boolean uploadCertificate(long certificateId, long hostId) {
453453 @ Override
454454 public boolean revokeCertificateAlias (String certificateAlias , String hypervisor , Long zoneId ) {
455455 HypervisorType hypervisorType = HypervisorType .getType (hypervisor );
456- List <HostVO > hosts = getRunningHostsToUploadCertificate (zoneId , hypervisorType );
457- s_logger .info ("Attempting to revoke certificate alias: " + certificateAlias + " from " + hosts .size () + " hosts" );
458- if (CollectionUtils .isNotEmpty (hosts )) {
459- for (HostVO host : hosts ) {
460- if (!revokeCertificateAliasFromHost (certificateAlias , host .getId ())) {
461- String msg = "Could not revoke certificate from host: " + host .getName () + " (" + host .getUuid () + ")" ;
456+ DirectDownloadCertificateVO certificateVO = directDownloadCertificateDao .findByAlias (certificateAlias , hypervisorType , zoneId );
457+ if (certificateVO == null ) {
458+ throw new CloudRuntimeException ("Certificate alias " + certificateAlias + " does not exist" );
459+ }
460+
461+ List <DirectDownloadCertificateHostMapVO > maps = directDownloadCertificateHostMapDao .listByCertificateId (certificateVO .getId ());
462+ s_logger .info ("Attempting to revoke certificate alias: " + certificateAlias + " from " + maps .size () + " hosts" );
463+ if (CollectionUtils .isNotEmpty (maps )) {
464+ for (DirectDownloadCertificateHostMapVO map : maps ) {
465+ Long hostId = map .getHostId ();
466+ if (!revokeCertificateAliasFromHost (certificateAlias , hostId )) {
467+ String msg = "Could not revoke certificate from host: " + hostId ;
462468 s_logger .error (msg );
463469 throw new CloudRuntimeException (msg );
464470 }
471+ directDownloadCertificateHostMapDao .remove (map .getId ());
465472 }
466473 }
467474 return true ;
0 commit comments