You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/04 11:02:55 UTC
[19/55] [abbrv] git commit: api_refactor: refactor template apis
api_refactor: refactor template apis
- Fix refactored apis, fix mapping in commands*.in
- Fix comments etc.
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/3e0b2164
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/3e0b2164
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/3e0b2164
Branch: refs/heads/api_refactoring
Commit: 3e0b2164be83a176304eb40d8000c15c0b63c310
Parents: e0b4430
Author: Rohit Yadav <bh...@apache.org>
Authored: Mon Dec 3 23:05:44 2012 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Mon Dec 3 23:05:44 2012 -0800
----------------------------------------------------------------------
.../com/cloud/api/commands/CreateTemplateCmd.java | 286 ---------------
.../com/cloud/api/commands/DeleteTemplateCmd.java | 118 ------
.../com/cloud/api/commands/ExtractTemplateCmd.java | 139 -------
.../api/commands/ListTemplatePermissionsCmd.java | 42 ---
.../com/cloud/api/commands/ListTemplatesCmd.java | 134 -------
.../com/cloud/api/commands/UpdateTemplateCmd.java | 78 ----
.../api/commands/UpdateTemplatePermissionsCmd.java | 50 ---
api/src/com/cloud/server/ManagementService.java | 4 +-
api/src/com/cloud/template/TemplateService.java | 4 +-
api/src/com/cloud/vm/UserVmService.java | 2 +-
.../user/template/command/CreateTemplateCmd.java | 286 +++++++++++++++
.../user/template/command/DeleteTemplateCmd.java | 118 ++++++
.../user/template/command/ExtractTemplateCmd.java | 139 +++++++
.../command/ListTemplatePermissionsCmd.java | 43 +++
.../user/template/command/ListTemplatesCmd.java | 134 +++++++
.../user/template/command/UpdateTemplateCmd.java | 79 ++++
.../command/UpdateTemplatePermissionsCmd.java | 51 +++
client/tomcatconf/commands.properties.in | 14 +-
.../cloud/baremetal/BareMetalVmManagerImpl.java | 2 +-
.../src/com/cloud/server/ManagementServerImpl.java | 4 +-
.../src/com/cloud/storage/swift/SwiftManager.java | 2 +-
.../com/cloud/storage/swift/SwiftManagerImpl.java | 2 +-
.../com/cloud/storage/upload/UploadListener.java | 2 +-
.../cloud/template/HyervisorTemplateAdapter.java | 2 +-
server/src/com/cloud/template/TemplateAdapter.java | 2 +-
.../com/cloud/template/TemplateAdapterBase.java | 2 +-
.../com/cloud/template/TemplateManagerImpl.java | 8 +-
server/src/com/cloud/vm/UserVmManagerImpl.java | 2 +-
.../test/com/cloud/vm/MockUserVmManagerImpl.java | 2 +-
29 files changed, 877 insertions(+), 874 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/CreateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateTemplateCmd.java b/api/src/com/cloud/api/commands/CreateTemplateCmd.java
deleted file mode 100755
index a9b28e2..0000000
--- a/api/src/com/cloud/api/commands/CreateTemplateCmd.java
+++ /dev/null
@@ -1,286 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCreateCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.StoragePoolResponse;
-import com.cloud.api.response.TemplateResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.PermissionDeniedException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.projects.Project;
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.Volume;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(responseObject = StoragePoolResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. "
- + "A template created from this command is automatically designated as a private template visible to the account that created it.")
- public class CreateTemplateCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName());
- private static final String s_name = "createtemplateresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.BITS, type = CommandType.INTEGER, description = "32 or 64 bit")
- private Integer bits;
-
- @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of the template. This is usually used for display purposes.", length=4096)
- private String displayText;
-
- @Parameter(name = ApiConstants.IS_FEATURED, type = CommandType.BOOLEAN, description = "true if this template is a featured template, false otherwise")
- private Boolean featured;
-
- @Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "true if this template is a public template, false otherwise")
- private Boolean publicTemplate;
-
- @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the template")
- private String templateName;
-
- @IdentityMapper(entityTableName="guest_os")
- @Parameter(name = ApiConstants.OS_TYPE_ID, type = CommandType.LONG, required = true, description = "the ID of the OS Type that best represents the OS of this template.")
- private Long osTypeId;
-
- @Parameter(name = ApiConstants.PASSWORD_ENABLED, type = CommandType.BOOLEAN, description = "true if the template supports the password reset feature; default is false")
- private Boolean passwordEnabled;
-
- @Parameter(name = ApiConstants.REQUIRES_HVM, type = CommandType.BOOLEAN, description = "true if the template requres HVM, false otherwise")
- private Boolean requiresHvm;
-
- @IdentityMapper(entityTableName="snapshots")
- @Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.LONG, description = "the ID of the snapshot the template is being created from. Either this parameter, or volumeId has to be passed in")
- private Long snapshotId;
-
- @IdentityMapper(entityTableName="volumes")
- @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.LONG, description = "the ID of the disk volume the template is being created from. Either this parameter, or snapshotId has to be passed in")
- private Long volumeId;
-
- @IdentityMapper(entityTableName="vm_instance")
- @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="Optional, VM ID. If this presents, it is going to create a baremetal template for VM this ID refers to. This is only for VM whose hypervisor type is BareMetal")
- private Long vmId;
-
- @Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="Optional, only for baremetal hypervisor. The directory name where template stored on CIFS server")
- private String url;
-
- @Parameter(name=ApiConstants.TEMPLATE_TAG, type=CommandType.STRING, description="the tag for this template.")
- private String templateTag;
-
- @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="Template details in key/value pairs.")
- protected Map details;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "vm_template";
- }
-
- public Integer getBits() {
- return bits;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public Boolean isFeatured() {
- return featured;
- }
-
- public Boolean isPublic() {
- return publicTemplate;
- }
-
- public String getTemplateName() {
- return templateName;
- }
-
- public Long getOsTypeId() {
- return osTypeId;
- }
-
- public Boolean isPasswordEnabled() {
- return passwordEnabled;
- }
-
- public Boolean getRequiresHvm() {
- return requiresHvm;
- }
-
- public Long getSnapshotId() {
- return snapshotId;
- }
-
- public Long getVolumeId() {
- return volumeId;
- }
-
- public Long getVmId() {
- return vmId;
- }
-
- public String getUrl() {
- return url;
- }
-
- public String getTemplateTag() {
- return templateTag;
- }
-
- public Map getDetails() {
- if (details == null || details.isEmpty()) {
- return null;
- }
-
- Collection paramsCollection = details.values();
- Map params = (Map) (paramsCollection.toArray())[0];
- return params;
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getResultObjectName() {
- return "template";
- }
-
- @Override
- public long getEntityOwnerId() {
- Long volumeId = getVolumeId();
- Long snapshotId = getSnapshotId();
- Long accountId = null;
- if (volumeId != null) {
- Volume volume = _entityMgr.findById(Volume.class, volumeId);
- if (volume != null) {
- accountId = volume.getAccountId();
- } else {
- throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
- }
- } else {
- Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
- if (snapshot != null) {
- accountId = snapshot.getAccountId();
- } else {
- throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
- }
- }
-
- Account account = _accountService.getAccount(accountId);
- //Can create templates for enabled projects/accounts only
- if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
- Project project = _projectService.findByProjectAccountId(accountId);
- if (project.getState() != Project.State.Active) {
- PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
- ex.addProxyObject(project, project.getId(), "projectId");
- }
- } else if (account.getState() == Account.State.disabled) {
- throw new PermissionDeniedException("The owner of template is disabled: " + account);
- }
-
- return accountId;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_TEMPLATE_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating template: " + getTemplateName();
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Template;
- }
-
- private boolean isBareMetal() {
- return (this.getVmId() != null && this.getUrl() != null);
- }
-
- @Override
- public void create() throws ResourceAllocationException {
- if (isBareMetal()) {
- _bareMetalVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
- /*Baremetal creates template record after taking image proceeded, use vmId as entity id here*/
- this.setEntityId(vmId);
- } else {
- VirtualMachineTemplate template = null;
- template = _userVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
- if (template != null) {
- this.setEntityId(template.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR,
- "Failed to create a template");
- }
- }
- }
-
- @Override
- public void execute() {
- UserContext.current().setEventDetails("Template Id: "+getEntityId()+((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
- VirtualMachineTemplate template = null;
- if (isBareMetal()) {
- template = _bareMetalVmService.createPrivateTemplate(this);
- } else {
- template = _userVmService.createPrivateTemplate(this);
- }
-
- if (template != null){
- List<TemplateResponse> templateResponses;
- if (isBareMetal()) {
- templateResponses = _responseGenerator.createTemplateResponses(template.getId(), vmId);
- } else {
- templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
- }
- TemplateResponse response = new TemplateResponse();
- if (templateResponses != null && !templateResponses.isEmpty()) {
- response = templateResponses.get(0);
- }
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private template");
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/DeleteTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java b/api/src/com/cloud/api/commands/DeleteTemplateCmd.java
deleted file mode 100755
index e3c995f..0000000
--- a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(responseObject=SuccessResponse.class, description="Deletes a template from the system. All virtual machines using the deleted template will not be affected.")
-public class DeleteTemplateCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(DeleteTemplateCmd.class.getName());
- private static final String s_name = "deletetemplateresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="vm_template")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the template")
- private Long id;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the ID of zone of the template")
- private Long zoneId;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getStaticName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
- if (template != null) {
- return template.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_TEMPLATE_DELETE;
- }
-
- @Override
- public String getEventDescription() {
- return "Deleting template " + getId();
- }
-
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Template;
- }
-
- public Long getInstanceId() {
- return getId();
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("Template Id: "+getId());
- boolean result = _templateService.deleteTemplate(this);
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete template");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/ExtractTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ExtractTemplateCmd.java b/api/src/com/cloud/api/commands/ExtractTemplateCmd.java
deleted file mode 100755
index eacd0f6..0000000
--- a/api/src/com/cloud/api/commands/ExtractTemplateCmd.java
+++ /dev/null
@@ -1,139 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.ExtractResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InternalErrorException;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Extracts a template", responseObject=ExtractResponse.class)
-public class ExtractTemplateCmd extends BaseAsyncCmd {
- public static final Logger s_logger = Logger.getLogger(ExtractTemplateCmd.class.getName());
-
- private static final String s_name = "extracttemplateresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="vm_template")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the template")
- private Long id;
-
- @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=false, description="the url to which the ISO would be extracted")
- private String url;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=false, description="the ID of the zone where the ISO is originally located" )
- private Long zoneId;
-
- @Parameter(name=ApiConstants.MODE, type=CommandType.STRING, required=true, description="the mode of extraction - HTTP_DOWNLOAD or FTP_UPLOAD")
- private String mode;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
- public String getUrl() {
- return url;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public String getMode() {
- return mode;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getStaticName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
- if (template != null) {
- return template.getAccountId();
- }
-
- // invalid id, parent this command to SYSTEM so ERROR events are tracked
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_TEMPLATE_EXTRACT;
- }
-
- @Override
- public String getEventDescription() {
- return "extracting template: " + getId() + " from zone: " + getZoneId();
- }
-
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Template;
- }
-
- public Long getInstanceId() {
- return getId();
- }
-
- @Override
- public void execute(){
- try {
- UserContext.current().setEventDetails(getEventDescription());
- Long uploadId = _templateService.extract(this);
- if (uploadId != null){
- ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract template");
- }
- } catch (InternalErrorException ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/ListTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListTemplatePermissionsCmd.java b/api/src/com/cloud/api/commands/ListTemplatePermissionsCmd.java
deleted file mode 100644
index 6e118d9..0000000
--- a/api/src/com/cloud/api/commands/ListTemplatePermissionsCmd.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.template.VirtualMachineTemplate;
-
-public class ListTemplatePermissionsCmd extends ListTemplateOrIsoPermissionsCmd {
- protected String getResponseName() {
- return "listtemplatepermissionsresponse";
- }
-
- @Override
- public String getMediaType() {
- return "template";
- }
-
- @Override
- protected Logger getLogger() {
- return Logger.getLogger(ListTemplatePermissionsCmd.class.getName());
- }
-
- protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
- return !template.getFormat().equals(ImageFormat.ISO);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListTemplatesCmd.java b/api/src/com/cloud/api/commands/ListTemplatesCmd.java
deleted file mode 100755
index ca5dd73..0000000
--- a/api/src/com/cloud/api/commands/ListTemplatesCmd.java
+++ /dev/null
@@ -1,134 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.TemplateResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.Pair;
-
-@Implementation(description="List all public, private, and privileged templates.", responseObject=TemplateResponse.class)
-public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
- public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName());
-
- private static final String s_name = "listtemplatesresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor for which to restrict the search")
- private String hypervisor;
-
- @IdentityMapper(entityTableName="vm_template")
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the template ID")
- private Long id;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the template name")
- private String templateName;
-
- @Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"self-executable\", \"executable\", and \"community\"." +
- "* featured-templates that are featured and are public" +
- "* self-templates that have been registered/created by the owner" +
- "* selfexecutable-templates that have been registered/created by the owner that can be used to deploy a new VM" +
- "* executable-all templates that can be used to deploy a new VM* community-templates that are public.")
- private String templateFilter;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list templates by zoneId")
- private Long zoneId;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getHypervisor() {
- return hypervisor;
- }
-
- public Long getId() {
- return id;
- }
-
- public String getTemplateName() {
- return templateName;
- }
-
- public String getTemplateFilter() {
- return templateFilter;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public boolean listInReadyState() {
-
- Account account = UserContext.current().getCaller();
- // It is account specific if account is admin type and domainId and accountName are not null
- boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
- // Show only those that are downloaded.
- TemplateFilter templateFilter = TemplateFilter.valueOf(getTemplateFilter());
- boolean onlyReady = (templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.selfexecutable) || (templateFilter == TemplateFilter.sharedexecutable)
- || (templateFilter == TemplateFilter.executable && isAccountSpecific) || (templateFilter == TemplateFilter.community);
- return onlyReady;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Template;
- }
-
- @Override
- public void execute(){
- Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
-
- ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
- List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
-
- for (Pair<Long, Long> template : templateZonePairSet) {
- List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
- responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState());
- templateResponses.addAll(responses);
- }
-
- response.setResponses(templateResponses);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/UpdateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateTemplateCmd.java b/api/src/com/cloud/api/commands/UpdateTemplateCmd.java
deleted file mode 100755
index 2cffdac..0000000
--- a/api/src/com/cloud/api/commands/UpdateTemplateCmd.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.TemplateResponse;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-
-@Implementation(description="Updates attributes of a template.", responseObject=TemplateResponse.class)
-public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
- public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
- private static final String s_name = "updatetemplateresponse";
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public Boolean isBootable() {
- return null;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @SuppressWarnings("unchecked")
- public TemplateResponse getResponse() {
- return null;
- }
-
- @Override
- public long getEntityOwnerId() {
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
- if (template != null) {
- return template.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute(){
- VirtualMachineTemplate result = _mgr.updateTemplate(this);
- if (result != null) {
- TemplateResponse response = _responseGenerator.createIsoResponse(result);
- response.setObjectName("template");
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java b/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java
deleted file mode 100644
index fac827b..0000000
--- a/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.Implementation;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-
-@Implementation(responseObject=SuccessResponse.class, description="Updates a template visibility permissions. " +
- "A public template is visible to all accounts within the same domain. " +
- "A private template is visible only to the owner of the template. " +
- "A priviledged template is a private template with account permissions added. " +
- "Only accounts specified under the template permissions are visible to them.")
-public class UpdateTemplatePermissionsCmd extends UpdateTemplateOrIsoPermissionsCmd {
- protected String getResponseName() {
- return "updatetemplatepermissionsresponse";
- }
-
- protected Logger getLogger() {
- return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName());
- }
-
- @Override
- public long getEntityOwnerId() {
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
- if (template != null) {
- return template.getAccountId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/server/ManagementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java
index 72769a0..2b06d75 100755
--- a/api/src/com/cloud/server/ManagementService.java
+++ b/api/src/com/cloud/server/ManagementService.java
@@ -28,6 +28,8 @@ import com.cloud.api.commands.CreateSSHKeyPairCmd;
import com.cloud.api.commands.DeleteSSHKeyPairCmd;
import com.cloud.api.commands.DestroySystemVmCmd;
import com.cloud.api.commands.ExtractVolumeCmd;
+import org.apache.cloudstack.api.user.template.command.ListTemplatesCmd;
+import org.apache.cloudstack.api.user.template.command.UpdateTemplateCmd;
import org.apache.cloudstack.api.user.vm.command.GetVMPasswordCmd;
import com.cloud.api.commands.ListAlertsCmd;
import com.cloud.api.commands.ListAsyncJobsCmd;
@@ -48,7 +50,6 @@ import com.cloud.api.commands.ListSSHKeyPairsCmd;
import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
-import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListVMGroupsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListZonesByCmd;
@@ -58,7 +59,6 @@ import com.cloud.api.commands.StopSystemVmCmd;
import com.cloud.api.commands.UpdateDomainCmd;
import com.cloud.api.commands.UpdateHostPasswordCmd;
import org.apache.cloudstack.api.user.iso.command.UpdateIsoCmd;
-import com.cloud.api.commands.UpdateTemplateCmd;
import com.cloud.api.commands.UpdateVMGroupCmd;
import com.cloud.api.commands.UpgradeSystemVMCmd;
import com.cloud.api.commands.UploadCustomCertificateCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/template/TemplateService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/template/TemplateService.java b/api/src/com/cloud/template/TemplateService.java
index c7f5f3d..9d63b25 100755
--- a/api/src/com/cloud/template/TemplateService.java
+++ b/api/src/com/cloud/template/TemplateService.java
@@ -21,9 +21,9 @@ import java.util.List;
import org.apache.cloudstack.api.user.template.command.CopyTemplateCmd;
import org.apache.cloudstack.api.user.iso.command.DeleteIsoCmd;
-import com.cloud.api.commands.DeleteTemplateCmd;
+import org.apache.cloudstack.api.user.template.command.DeleteTemplateCmd;
import org.apache.cloudstack.api.user.iso.command.ExtractIsoCmd;
-import com.cloud.api.commands.ExtractTemplateCmd;
+import org.apache.cloudstack.api.user.template.command.ExtractTemplateCmd;
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
import com.cloud.api.commands.RegisterIsoCmd;
import com.cloud.api.commands.RegisterTemplateCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java
index 5a1ff5d..6c9afd2 100755
--- a/api/src/com/cloud/vm/UserVmService.java
+++ b/api/src/com/cloud/vm/UserVmService.java
@@ -23,7 +23,7 @@ import javax.naming.InsufficientResourcesException;
import org.apache.cloudstack.api.admin.vm.command.AssignVMCmd;
import com.cloud.api.commands.AttachVolumeCmd;
-import com.cloud.api.commands.CreateTemplateCmd;
+import org.apache.cloudstack.api.user.template.command.CreateTemplateCmd;
import com.cloud.api.commands.CreateVMGroupCmd;
import com.cloud.api.commands.DeleteVMGroupCmd;
import org.apache.cloudstack.api.user.vm.command.DeployVMCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/CreateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/CreateTemplateCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/CreateTemplateCmd.java
new file mode 100755
index 0000000..0a2b970
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/CreateTemplateCmd.java
@@ -0,0 +1,286 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.StoragePoolResponse;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.projects.Project;
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(responseObject = StoragePoolResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. "
+ + "A template created from this command is automatically designated as a private template visible to the account that created it.")
+ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName());
+ private static final String s_name = "createtemplateresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.BITS, type = CommandType.INTEGER, description = "32 or 64 bit")
+ private Integer bits;
+
+ @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of the template. This is usually used for display purposes.", length=4096)
+ private String displayText;
+
+ @Parameter(name = ApiConstants.IS_FEATURED, type = CommandType.BOOLEAN, description = "true if this template is a featured template, false otherwise")
+ private Boolean featured;
+
+ @Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "true if this template is a public template, false otherwise")
+ private Boolean publicTemplate;
+
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the template")
+ private String templateName;
+
+ @IdentityMapper(entityTableName="guest_os")
+ @Parameter(name = ApiConstants.OS_TYPE_ID, type = CommandType.LONG, required = true, description = "the ID of the OS Type that best represents the OS of this template.")
+ private Long osTypeId;
+
+ @Parameter(name = ApiConstants.PASSWORD_ENABLED, type = CommandType.BOOLEAN, description = "true if the template supports the password reset feature; default is false")
+ private Boolean passwordEnabled;
+
+ @Parameter(name = ApiConstants.REQUIRES_HVM, type = CommandType.BOOLEAN, description = "true if the template requres HVM, false otherwise")
+ private Boolean requiresHvm;
+
+ @IdentityMapper(entityTableName="snapshots")
+ @Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.LONG, description = "the ID of the snapshot the template is being created from. Either this parameter, or volumeId has to be passed in")
+ private Long snapshotId;
+
+ @IdentityMapper(entityTableName="volumes")
+ @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.LONG, description = "the ID of the disk volume the template is being created from. Either this parameter, or snapshotId has to be passed in")
+ private Long volumeId;
+
+ @IdentityMapper(entityTableName="vm_instance")
+ @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="Optional, VM ID. If this presents, it is going to create a baremetal template for VM this ID refers to. This is only for VM whose hypervisor type is BareMetal")
+ private Long vmId;
+
+ @Parameter(name=ApiConstants.URL, type=CommandType.STRING, description="Optional, only for baremetal hypervisor. The directory name where template stored on CIFS server")
+ private String url;
+
+ @Parameter(name=ApiConstants.TEMPLATE_TAG, type=CommandType.STRING, description="the tag for this template.")
+ private String templateTag;
+
+ @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="Template details in key/value pairs.")
+ protected Map details;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "vm_template";
+ }
+
+ public Integer getBits() {
+ return bits;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public Boolean isFeatured() {
+ return featured;
+ }
+
+ public Boolean isPublic() {
+ return publicTemplate;
+ }
+
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public Long getOsTypeId() {
+ return osTypeId;
+ }
+
+ public Boolean isPasswordEnabled() {
+ return passwordEnabled;
+ }
+
+ public Boolean getRequiresHvm() {
+ return requiresHvm;
+ }
+
+ public Long getSnapshotId() {
+ return snapshotId;
+ }
+
+ public Long getVolumeId() {
+ return volumeId;
+ }
+
+ public Long getVmId() {
+ return vmId;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public String getTemplateTag() {
+ return templateTag;
+ }
+
+ public Map getDetails() {
+ if (details == null || details.isEmpty()) {
+ return null;
+ }
+
+ Collection paramsCollection = details.values();
+ Map params = (Map) (paramsCollection.toArray())[0];
+ return params;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getResultObjectName() {
+ return "template";
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long volumeId = getVolumeId();
+ Long snapshotId = getSnapshotId();
+ Long accountId = null;
+ if (volumeId != null) {
+ Volume volume = _entityMgr.findById(Volume.class, volumeId);
+ if (volume != null) {
+ accountId = volume.getAccountId();
+ } else {
+ throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
+ }
+ } else {
+ Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
+ if (snapshot != null) {
+ accountId = snapshot.getAccountId();
+ } else {
+ throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
+ }
+ }
+
+ Account account = _accountService.getAccount(accountId);
+ //Can create templates for enabled projects/accounts only
+ if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+ Project project = _projectService.findByProjectAccountId(accountId);
+ if (project.getState() != Project.State.Active) {
+ PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
+ ex.addProxyObject(project, project.getId(), "projectId");
+ }
+ } else if (account.getState() == Account.State.disabled) {
+ throw new PermissionDeniedException("The owner of template is disabled: " + account);
+ }
+
+ return accountId;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_TEMPLATE_CREATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "creating template: " + getTemplateName();
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ private boolean isBareMetal() {
+ return (this.getVmId() != null && this.getUrl() != null);
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException {
+ if (isBareMetal()) {
+ _bareMetalVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
+ /*Baremetal creates template record after taking image proceeded, use vmId as entity id here*/
+ this.setEntityId(vmId);
+ } else {
+ VirtualMachineTemplate template = null;
+ template = _userVmService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
+ if (template != null) {
+ this.setEntityId(template.getId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR,
+ "Failed to create a template");
+ }
+ }
+ }
+
+ @Override
+ public void execute() {
+ UserContext.current().setEventDetails("Template Id: "+getEntityId()+((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
+ VirtualMachineTemplate template = null;
+ if (isBareMetal()) {
+ template = _bareMetalVmService.createPrivateTemplate(this);
+ } else {
+ template = _userVmService.createPrivateTemplate(this);
+ }
+
+ if (template != null){
+ List<TemplateResponse> templateResponses;
+ if (isBareMetal()) {
+ templateResponses = _responseGenerator.createTemplateResponses(template.getId(), vmId);
+ } else {
+ templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
+ }
+ TemplateResponse response = new TemplateResponse();
+ if (templateResponses != null && !templateResponses.isEmpty()) {
+ response = templateResponses.get(0);
+ }
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private template");
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/DeleteTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/DeleteTemplateCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/DeleteTemplateCmd.java
new file mode 100755
index 0000000..c0e5812
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/DeleteTemplateCmd.java
@@ -0,0 +1,118 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(responseObject=SuccessResponse.class, description="Deletes a template from the system. All virtual machines using the deleted template will not be affected.")
+public class DeleteTemplateCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteTemplateCmd.class.getName());
+ private static final String s_name = "deletetemplateresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="vm_template")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the template")
+ private Long id;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the ID of zone of the template")
+ private Long zoneId;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getStaticName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_TEMPLATE_DELETE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Deleting template " + getId();
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ public Long getInstanceId() {
+ return getId();
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Template Id: "+getId());
+ boolean result = _templateService.deleteTemplate(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete template");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/ExtractTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/ExtractTemplateCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/ExtractTemplateCmd.java
new file mode 100755
index 0000000..6de5118
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/ExtractTemplateCmd.java
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.ExtractResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InternalErrorException;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Extracts a template", responseObject=ExtractResponse.class)
+public class ExtractTemplateCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(ExtractTemplateCmd.class.getName());
+
+ private static final String s_name = "extracttemplateresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="vm_template")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the template")
+ private Long id;
+
+ @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=false, description="the url to which the ISO would be extracted")
+ private String url;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=false, description="the ID of the zone where the ISO is originally located" )
+ private Long zoneId;
+
+ @Parameter(name=ApiConstants.MODE, type=CommandType.STRING, required=true, description="the mode of extraction - HTTP_DOWNLOAD or FTP_UPLOAD")
+ private String mode;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public String getMode() {
+ return mode;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public static String getStaticName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ // invalid id, parent this command to SYSTEM so ERROR events are tracked
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_TEMPLATE_EXTRACT;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "extracting template: " + getId() + " from zone: " + getZoneId();
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ public Long getInstanceId() {
+ return getId();
+ }
+
+ @Override
+ public void execute(){
+ try {
+ UserContext.current().setEventDetails(getEventDescription());
+ Long uploadId = _templateService.extract(this);
+ if (uploadId != null){
+ ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract template");
+ }
+ } catch (InternalErrorException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatePermissionsCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatePermissionsCmd.java
new file mode 100644
index 0000000..8188032
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatePermissionsCmd.java
@@ -0,0 +1,43 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
+import org.apache.log4j.Logger;
+
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.template.VirtualMachineTemplate;
+
+public class ListTemplatePermissionsCmd extends ListTemplateOrIsoPermissionsCmd {
+ protected String getResponseName() {
+ return "listtemplatepermissionsresponse";
+ }
+
+ @Override
+ public String getMediaType() {
+ return "template";
+ }
+
+ @Override
+ protected Logger getLogger() {
+ return Logger.getLogger(ListTemplatePermissionsCmd.class.getName());
+ }
+
+ protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
+ return !template.getFormat().equals(ImageFormat.ISO);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatesCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatesCmd.java
new file mode 100755
index 0000000..7d2cc01
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/ListTemplatesCmd.java
@@ -0,0 +1,134 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.utils.Pair;
+
+@Implementation(description="List all public, private, and privileged templates.", responseObject=TemplateResponse.class)
+public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName());
+
+ private static final String s_name = "listtemplatesresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the hypervisor for which to restrict the search")
+ private String hypervisor;
+
+ @IdentityMapper(entityTableName="vm_template")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the template ID")
+ private Long id;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the template name")
+ private String templateName;
+
+ @Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"self-executable\", \"executable\", and \"community\"." +
+ "* featured-templates that are featured and are public" +
+ "* self-templates that have been registered/created by the owner" +
+ "* selfexecutable-templates that have been registered/created by the owner that can be used to deploy a new VM" +
+ "* executable-all templates that can be used to deploy a new VM* community-templates that are public.")
+ private String templateFilter;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list templates by zoneId")
+ private Long zoneId;
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getHypervisor() {
+ return hypervisor;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public String getTemplateFilter() {
+ return templateFilter;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public boolean listInReadyState() {
+
+ Account account = UserContext.current().getCaller();
+ // It is account specific if account is admin type and domainId and accountName are not null
+ boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
+ // Show only those that are downloaded.
+ TemplateFilter templateFilter = TemplateFilter.valueOf(getTemplateFilter());
+ boolean onlyReady = (templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.selfexecutable) || (templateFilter == TemplateFilter.sharedexecutable)
+ || (templateFilter == TemplateFilter.executable && isAccountSpecific) || (templateFilter == TemplateFilter.community);
+ return onlyReady;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.Template;
+ }
+
+ @Override
+ public void execute(){
+ Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
+
+ ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
+ List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
+
+ for (Pair<Long, Long> template : templateZonePairSet) {
+ List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
+ responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState());
+ templateResponses.addAll(responses);
+ }
+
+ response.setResponses(templateResponses);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplateCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplateCmd.java
new file mode 100755
index 0000000..bfde98e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplateCmd.java
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.TemplateResponse;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+
+@Implementation(description="Updates attributes of a template.", responseObject=TemplateResponse.class)
+public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd {
+ public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
+ private static final String s_name = "updatetemplateresponse";
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public Boolean isBootable() {
+ return null;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @SuppressWarnings("unchecked")
+ public TemplateResponse getResponse() {
+ return null;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ VirtualMachineTemplate result = _mgr.updateTemplate(this);
+ if (result != null) {
+ TemplateResponse response = _responseGenerator.createIsoResponse(result);
+ response.setObjectName("template");
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplatePermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplatePermissionsCmd.java b/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplatePermissionsCmd.java
new file mode 100644
index 0000000..3fd09da
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/user/template/command/UpdateTemplatePermissionsCmd.java
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.user.template.command;
+
+import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.Implementation;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+
+@Implementation(responseObject=SuccessResponse.class, description="Updates a template visibility permissions. " +
+ "A public template is visible to all accounts within the same domain. " +
+ "A private template is visible only to the owner of the template. " +
+ "A priviledged template is a private template with account permissions added. " +
+ "Only accounts specified under the template permissions are visible to them.")
+public class UpdateTemplatePermissionsCmd extends UpdateTemplateOrIsoPermissionsCmd {
+ protected String getResponseName() {
+ return "updatetemplatepermissionsresponse";
+ }
+
+ protected Logger getLogger() {
+ return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName());
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
+ if (template != null) {
+ return template.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 57ddd9a..c6f5409 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -79,15 +79,15 @@ listSnapshotPolicies=com.cloud.api.commands.ListSnapshotPoliciesCmd;15
#### template commands
-createTemplate=com.cloud.api.commands.CreateTemplateCmd;15
+createTemplate=org.apache.cloudstack.api.user.template.command.CreateTemplateCmd;15
registerTemplate=com.cloud.api.commands.RegisterTemplateCmd;15
-updateTemplate=com.cloud.api.commands.UpdateTemplateCmd;15
+updateTemplate=org.apache.cloudstack.api.user.template.command.UpdateTemplateCmd;15
copyTemplate=org.apache.cloudstack.api.user.template.command.CopyTemplateCmd;15
-deleteTemplate=com.cloud.api.commands.DeleteTemplateCmd;15
-listTemplates=com.cloud.api.commands.ListTemplatesCmd;15
-updateTemplatePermissions=com.cloud.api.commands.UpdateTemplatePermissionsCmd;15
-listTemplatePermissions=com.cloud.api.commands.ListTemplatePermissionsCmd;15
-extractTemplate=com.cloud.api.commands.ExtractTemplateCmd;15
+deleteTemplate=org.apache.cloudstack.api.user.template.command.DeleteTemplateCmd;15
+listTemplates=org.apache.cloudstack.api.user.template.command.ListTemplatesCmd;15
+updateTemplatePermissions=org.apache.cloudstack.api.user.template.command.UpdateTemplatePermissionsCmd;15
+listTemplatePermissions=org.apache.cloudstack.api.user.template.command.ListTemplatePermissionsCmd;15
+extractTemplate=org.apache.cloudstack.api.user.template.command.ExtractTemplateCmd;15
prepareTemplate=com.cloud.api.commands.PrepareTemplateCmd;1
#### iso commands
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
index fc0ecb5..e0ce531 100755
--- a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
+++ b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
@@ -25,6 +25,7 @@ import java.util.concurrent.Executors;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
+import org.apache.cloudstack.api.user.template.command.CreateTemplateCmd;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
@@ -33,7 +34,6 @@ import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
import com.cloud.agent.api.baremetal.IpmiBootorResetCommand;
import com.cloud.agent.manager.Commands;
import com.cloud.api.commands.AttachVolumeCmd;
-import com.cloud.api.commands.CreateTemplateCmd;
import org.apache.cloudstack.api.user.vm.command.DeployVMCmd;
import com.cloud.api.commands.DetachVolumeCmd;
import org.apache.cloudstack.api.user.vm.command.StartVMCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index 2f33c25..c43dbd3 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -43,6 +43,8 @@ import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.cloudstack.api.user.iso.command.ListIsosCmd;
+import org.apache.cloudstack.api.user.template.command.ListTemplatesCmd;
+import org.apache.cloudstack.api.user.template.command.UpdateTemplateCmd;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
@@ -82,7 +84,6 @@ import com.cloud.api.commands.ListSSHKeyPairsCmd;
import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
-import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListVMGroupsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListZonesByCmd;
@@ -92,7 +93,6 @@ import com.cloud.api.commands.StopSystemVmCmd;
import com.cloud.api.commands.UpdateDomainCmd;
import com.cloud.api.commands.UpdateHostPasswordCmd;
import org.apache.cloudstack.api.user.iso.command.UpdateIsoCmd;
-import com.cloud.api.commands.UpdateTemplateCmd;
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
import com.cloud.api.commands.UpdateVMGroupCmd;
import com.cloud.api.commands.UpgradeSystemVMCmd;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/server/src/com/cloud/storage/swift/SwiftManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/swift/SwiftManager.java b/server/src/com/cloud/storage/swift/SwiftManager.java
index 8fd3eb0..a1bd42d 100644
--- a/server/src/com/cloud/storage/swift/SwiftManager.java
+++ b/server/src/com/cloud/storage/swift/SwiftManager.java
@@ -21,7 +21,7 @@ import java.util.List;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.api.commands.AddSwiftCmd;
import org.apache.cloudstack.api.user.iso.command.DeleteIsoCmd;
-import com.cloud.api.commands.DeleteTemplateCmd;
+import org.apache.cloudstack.api.user.template.command.DeleteTemplateCmd;
import com.cloud.api.commands.ListSwiftsCmd;
import com.cloud.exception.DiscoveryException;
import com.cloud.storage.Swift;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3e0b2164/server/src/com/cloud/storage/swift/SwiftManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java
index 207d9eb..1708193 100644
--- a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java
+++ b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java
@@ -26,6 +26,7 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.user.iso.command.DeleteIsoCmd;
+import org.apache.cloudstack.api.user.template.command.DeleteTemplateCmd;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
@@ -33,7 +34,6 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.DeleteObjectFromSwiftCommand;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.api.commands.AddSwiftCmd;
-import com.cloud.api.commands.DeleteTemplateCmd;
import com.cloud.api.commands.ListSwiftsCmd;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;