9898import com .cloud .dc .DataCenterVO ;
9999import com .cloud .dc .dao .ClusterDao ;
100100import com .cloud .dc .dao .DataCenterDao ;
101+ import com .cloud .domain .Domain ;
101102import com .cloud .domain .dao .DomainDao ;
102103import com .cloud .event .ActionEvent ;
103104import com .cloud .event .EventTypes ;
@@ -396,9 +397,7 @@ public String extract(ExtractTemplateCmd cmd) {
396397 if (template == null ) {
397398 throw new InvalidParameterValueException ("unable to find template with id " + templateId );
398399 }
399- TemplateAdapter adapter = getAdapter (template .getHypervisorType ());
400- TemplateProfile profile = adapter .prepareExtractTemplate (cmd );
401-
400+
402401 return extract (caller , templateId , url , zoneId , mode , eventId , false );
403402 }
404403
@@ -711,7 +710,7 @@ public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUn
711710 throw new InvalidParameterValueException ("There is no template " + templateId + " in zone " + sourceZoneId );
712711 }
713712 if (srcSecStore .getScope ().getScopeType () == ScopeType .REGION ) {
714- s_logger .debug ("Template " + templateId + " is in region-wide secondary storage " + dstSecStore .getName () + " , don't need to copy" );
713+ s_logger .debug ("Template " + templateId + " is in region-wide secondary storage " + srcSecStore .getName () + " , don't need to copy" );
715714 return template ;
716715 }
717716
@@ -809,9 +808,6 @@ public boolean stop() {
809808
810809 @ Override
811810 public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
812-
813- final Map <String , String > configs = _configDao .getConfiguration ("AgentManager" , params );
814-
815811 String value = _configDao .getValue (Config .PrimaryStorageDownloadWait .toString ());
816812 _primaryStorageDownloadWait = NumbersUtil .parseInt (value , Integer .parseInt (Config .PrimaryStorageDownloadWait .getDefaultValue ()));
817813
@@ -1237,8 +1233,8 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
12371233 }
12381234 }
12391235
1240- Long accountId = template .getAccountId ();
1241- if (accountId == null ) {
1236+ Long ownerId = template .getAccountId ();
1237+ if (ownerId == null ) {
12421238 // if there is no owner of the template then it's probably already a
12431239 // public template (or domain private template) so
12441240 // publishing to individual users is irrelevant
@@ -1270,12 +1266,19 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
12701266 }
12711267
12721268 _tmpltDao .update (template .getId (), updatedTemplate );
1269+
1270+ //when operation is add/remove, accountNames can not be null
1271+ if (("add" .equalsIgnoreCase (operation ) || "remove" .equalsIgnoreCase (operation )) && accountNames == null ) {
1272+ throw new InvalidParameterValueException ("Operation " + operation + " requires accounts or projectIds to be passed in" );
1273+ }
12731274
1274- Long domainId = caller .getDomainId ();
1275+ //Derive the domain id from the template owner as updateTemplatePermissions is not cross domain operation
1276+ Account owner = _accountMgr .getAccount (ownerId );
1277+ Domain domain = _domainDao .findById (owner .getDomainId ());
12751278 if ("add" .equalsIgnoreCase (operation )) {
12761279 txn .start ();
12771280 for (String accountName : accountNames ) {
1278- Account permittedAccount = _accountDao .findActiveAccount (accountName , domainId );
1281+ Account permittedAccount = _accountDao .findActiveAccount (accountName , domain . getId () );
12791282 if (permittedAccount != null ) {
12801283 if (permittedAccount .getId () == caller .getId ()) {
12811284 continue ; // don't grant permission to the template
@@ -1288,15 +1291,15 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
12881291 }
12891292 } else {
12901293 txn .rollback ();
1291- throw new InvalidParameterValueException ("Unable to grant a launch permission to account " + accountName
1294+ throw new InvalidParameterValueException ("Unable to grant a launch permission to account " + accountName + " in domain id=" + domain . getUuid ()
12921295 + ", account not found. " + "No permissions updated, please verify the account names and retry." );
12931296 }
12941297 }
12951298 txn .commit ();
12961299 } else if ("remove" .equalsIgnoreCase (operation )) {
12971300 List <Long > accountIds = new ArrayList <Long >();
12981301 for (String accountName : accountNames ) {
1299- Account permittedAccount = _accountDao .findActiveAccount (accountName , domainId );
1302+ Account permittedAccount = _accountDao .findActiveAccount (accountName , domain . getId () );
13001303 if (permittedAccount != null ) {
13011304 accountIds .add (permittedAccount .getId ());
13021305 }
@@ -1314,10 +1317,6 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
13141317 return true ;
13151318 }
13161319
1317- private String getRandomPrivateTemplateName () {
1318- return UUID .randomUUID ().toString ();
1319- }
1320-
13211320 @ Override
13221321 @ DB
13231322 @ ActionEvent (eventType = EventTypes .EVENT_TEMPLATE_CREATE , eventDescription = "creating template" , async = true )
@@ -1525,8 +1524,7 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
15251524 throw new InvalidParameterValueException ("Failed to create private template record, unable to find snapshot " + snapshotId );
15261525 }
15271526
1528- volume = _volumeDao .findById (snapshot .getVolumeId ());
1529- VolumeVO snapshotVolume = _volumeDao .findByIdIncludingRemoved (snapshot .getVolumeId ());
1527+ volume = this ._volumeDao .findById (snapshot .getVolumeId ());
15301528
15311529 // check permissions
15321530 _accountMgr .checkAccess (caller , null , true , snapshot );
0 commit comments