mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Refactor listTemplatesCmd and listIsoCmd to use db view.
This commit is contained in:
parent
7ba1a8fa21
commit
539824797c
@ -219,28 +219,6 @@ public interface ManagementService {
|
||||
*/
|
||||
List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
|
||||
|
||||
/**
|
||||
* List ISOs that match the specified criteria.
|
||||
*
|
||||
* @param cmd
|
||||
* The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
|
||||
* and zoneId
|
||||
* parameters.
|
||||
* @return list of ISOs
|
||||
*/
|
||||
Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd);
|
||||
|
||||
/**
|
||||
* List templates that match the specified criteria.
|
||||
*
|
||||
* @param cmd
|
||||
* The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
|
||||
* and zoneId
|
||||
* parameters.
|
||||
* @return list of ISOs
|
||||
*/
|
||||
Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd);
|
||||
|
||||
|
||||
/**
|
||||
* List system VMs by the given search criteria
|
||||
|
||||
@ -241,7 +241,7 @@ public interface ResponseGenerator {
|
||||
|
||||
Host findHostById(Long hostId);
|
||||
|
||||
List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
|
||||
//List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
|
||||
|
||||
VpnUsersResponse createVpnUserResponse(VpnUser user);
|
||||
|
||||
@ -267,7 +267,9 @@ public interface ResponseGenerator {
|
||||
|
||||
//List<EventResponse> createEventResponse(EventJoinVO... events);
|
||||
|
||||
TemplateResponse createIsoResponse(VirtualMachineTemplate result);
|
||||
TemplateResponse createTemplateUpdateResponse(VirtualMachineTemplate result);
|
||||
|
||||
List<TemplateResponse> createTemplateResponses(VirtualMachineTemplate result, Long zoneId, boolean readyOnly);
|
||||
|
||||
List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
|
||||
|
||||
@ -287,13 +289,13 @@ public interface ResponseGenerator {
|
||||
|
||||
Long getSecurityGroupId(String groupName, long accountId);
|
||||
|
||||
List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
|
||||
List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, Long zoneId, boolean readyOnly);
|
||||
|
||||
// List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
|
||||
//List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
|
||||
|
||||
ProjectResponse createProjectResponse(Project project);
|
||||
|
||||
|
||||
List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
|
||||
|
||||
List<TemplateResponse> createTemplateResponses(long templateId, Long vmId);
|
||||
|
||||
FirewallResponse createFirewallResponse(FirewallRule fwRule);
|
||||
|
||||
@ -80,7 +80,7 @@ public class PrepareTemplateCmd extends BaseCmd {
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
|
||||
VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId);
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate.getId(), zoneId, true);
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate, zoneId, true);
|
||||
response.setResponses(templateResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -148,16 +148,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Set<Pair<Long, Long>> isoZonePairSet = _mgr.listIsos(this);
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
|
||||
|
||||
for (Pair<Long, Long> iso : isoZonePairSet) {
|
||||
List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
|
||||
responses = _responseGenerator.createIsoResponses(iso.first(), iso.second(), listInReadyState());
|
||||
templateResponses.addAll(responses);
|
||||
}
|
||||
response.setResponses(templateResponses);
|
||||
ListResponse<TemplateResponse> response = _queryService.listIsos(this);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public class RegisterIsoCmd extends BaseCmd {
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
|
||||
description="Register iso for the project")
|
||||
private Long projectId;
|
||||
|
||||
|
||||
@Parameter(name=ApiConstants.IMAGE_STORE_UUID, type=CommandType.STRING,
|
||||
description="Image store uuid")
|
||||
private String imageStoreUuid;
|
||||
@ -144,7 +144,7 @@ public class RegisterIsoCmd extends BaseCmd {
|
||||
public String getChecksum() {
|
||||
return checksum;
|
||||
}
|
||||
|
||||
|
||||
public String getImageStoreUuid() {
|
||||
return this.imageStoreUuid;
|
||||
}
|
||||
@ -173,7 +173,7 @@ public class RegisterIsoCmd extends BaseCmd {
|
||||
VirtualMachineTemplate template = _templateService.registerIso(this);
|
||||
if (template != null) {
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template, zoneId, false);
|
||||
response.setResponses(templateResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -68,7 +68,7 @@ public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd {
|
||||
public void execute(){
|
||||
VirtualMachineTemplate result = _templateService.updateTemplate(this);
|
||||
if (result != null) {
|
||||
TemplateResponse response = _responseGenerator.createIsoResponse(result);
|
||||
TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
|
||||
@ -124,7 +124,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
|
||||
VirtualMachineTemplate template = _templateService.copyTemplate(this);
|
||||
|
||||
if (template != null){
|
||||
List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
|
||||
List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template, getDestinationZoneId(), false);
|
||||
TemplateResponse response = new TemplateResponse();
|
||||
if (listResponse != null && !listResponse.isEmpty()) {
|
||||
response = listResponse.get(0);
|
||||
|
||||
@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -55,7 +56,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
|
||||
@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\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " +
|
||||
@Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " +
|
||||
"* featured : templates that have been marked as featured and public. " +
|
||||
"* self : templates that have been registered or created by the calling user. " +
|
||||
"* selfexecutable : same as self, but only returns templates that can be used to deploy a new VM. " +
|
||||
@ -119,18 +120,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
|
||||
|
||||
@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);
|
||||
ListResponse<TemplateResponse> response = _queryService.listTemplates(this);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ public class RegisterTemplateCmd extends BaseCmd {
|
||||
VirtualMachineTemplate template = _templateService.registerTemplate(this);
|
||||
if (template != null){
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template.getId(), zoneId, false);
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template, zoneId, false);
|
||||
response.setResponses(templateResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -68,7 +68,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd {
|
||||
public void execute(){
|
||||
VirtualMachineTemplate result = _templateService.updateTemplate(this);
|
||||
if (result != null) {
|
||||
TemplateResponse response = _responseGenerator.createIsoResponse(result);
|
||||
TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
|
||||
response.setObjectName("template");
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -17,8 +17,10 @@
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
@ -31,7 +33,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
@EntityReference(value=VirtualMachineTemplate.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class TemplateResponse extends BaseResponse implements ControlledEntityResponse {
|
||||
public class TemplateResponse extends BaseResponse implements ControlledViewEntityResponse {
|
||||
@SerializedName(ApiConstants.ID) @Param(description="the template ID")
|
||||
private String id;
|
||||
|
||||
@ -82,6 +84,8 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
|
||||
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the account name to which the template belongs")
|
||||
private String account;
|
||||
|
||||
//TODO: since a template can be associated to more than one zones, this model is not accurate. For backward-compatibility, keep these fields
|
||||
// here, but add a zones field to capture multiple zones.
|
||||
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for this template")
|
||||
private String zoneId;
|
||||
|
||||
@ -133,12 +137,20 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
|
||||
@SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with template")
|
||||
private Map details;
|
||||
|
||||
@SerializedName("zones") @Param(description="list of zones associated with tempate", responseObject = TemplateZoneResponse.class)
|
||||
private Set<TemplateZoneResponse> zones;
|
||||
|
||||
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with tempate", responseObject = ResourceTagResponse.class)
|
||||
private List<ResourceTagResponse> tags;
|
||||
private Set<ResourceTagResponse> tags;
|
||||
|
||||
@SerializedName(ApiConstants.SSHKEY_ENABLED) @Param(description="true if template is sshkey enabled, false otherwise")
|
||||
private Boolean sshKeyEnabled;
|
||||
|
||||
public TemplateResponse(){
|
||||
zones = new LinkedHashSet<TemplateZoneResponse>();
|
||||
tags = new LinkedHashSet<ResourceTagResponse>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectId() {
|
||||
return this.getId();
|
||||
@ -288,12 +300,29 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void setTags(List<ResourceTagResponse> tags) {
|
||||
public void setTags(Set<ResourceTagResponse> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public void addTag(ResourceTagResponse tag){
|
||||
this.tags.add(tag);
|
||||
}
|
||||
|
||||
public void setZones(Set<TemplateZoneResponse> zones){
|
||||
this.zones = zones;
|
||||
}
|
||||
|
||||
public void addZone(TemplateZoneResponse zone){
|
||||
this.zones.add(zone);
|
||||
}
|
||||
|
||||
public void setSshKeyEnabled(boolean sshKeyEnabled) {
|
||||
this.sshKeyEnabled = sshKeyEnabled;
|
||||
}
|
||||
|
||||
public String getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
// 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.response;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class TemplateZoneResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for the template")
|
||||
private String zoneId;
|
||||
|
||||
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the zone for the template")
|
||||
private String zoneName;
|
||||
|
||||
|
||||
public TemplateZoneResponse(){
|
||||
super();
|
||||
}
|
||||
|
||||
public TemplateZoneResponse(String zoneId, String zoneName){
|
||||
super();
|
||||
this.zoneId = zoneId;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setZoneId(String zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
public void setZoneName(String zoneName) {
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
String oid = this.getZoneId();
|
||||
result = prime * result + ((oid== null) ? 0 : oid.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TemplateZoneResponse other = (TemplateZoneResponse) obj;
|
||||
String oid = this.getZoneId();
|
||||
if (oid == null) {
|
||||
if (other.getZoneId() != null)
|
||||
return false;
|
||||
} else if (!oid.equals(other.getZoneId()))
|
||||
return false;
|
||||
else if ( this.getZoneName().equals(other.getZoneName()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,6 +24,7 @@ import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
|
||||
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
|
||||
import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
|
||||
@ -31,6 +32,7 @@ import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
|
||||
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
|
||||
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
|
||||
import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
|
||||
import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
|
||||
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
|
||||
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
|
||||
@ -51,6 +53,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
@ -101,4 +104,8 @@ public interface QueryService {
|
||||
public ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd);
|
||||
|
||||
public ListResponse<ZoneResponse> listDataCenters(ListZonesByCmd cmd);
|
||||
|
||||
public ListResponse<TemplateResponse> listTemplates(ListTemplatesCmd cmd);
|
||||
|
||||
public ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd);
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
@ -65,6 +66,7 @@ import com.cloud.api.query.dao.ResourceTagJoinDao;
|
||||
import com.cloud.api.query.dao.SecurityGroupJoinDao;
|
||||
import com.cloud.api.query.dao.ServiceOfferingJoinDao;
|
||||
import com.cloud.api.query.dao.StoragePoolJoinDao;
|
||||
import com.cloud.api.query.dao.TemplateJoinDao;
|
||||
import com.cloud.api.query.dao.UserAccountJoinDao;
|
||||
import com.cloud.api.query.dao.UserVmJoinDao;
|
||||
import com.cloud.api.query.dao.VolumeJoinDao;
|
||||
@ -84,6 +86,7 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.api.query.vo.SecurityGroupJoinVO;
|
||||
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
|
||||
import com.cloud.api.query.vo.StoragePoolJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.api.query.vo.UserAccountJoinVO;
|
||||
import com.cloud.api.query.vo.UserVmJoinVO;
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
@ -240,6 +243,7 @@ import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeHostDao;
|
||||
import com.cloud.storage.snapshot.SnapshotPolicy;
|
||||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountDetailsDao;
|
||||
import com.cloud.user.AccountVO;
|
||||
@ -369,6 +373,7 @@ public class ApiDBUtils {
|
||||
static ImageStoreJoinDao _imageStoreJoinDao;
|
||||
static AccountJoinDao _accountJoinDao;
|
||||
static AsyncJobJoinDao _jobJoinDao;
|
||||
static TemplateJoinDao _templateJoinDao;
|
||||
|
||||
static PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
|
||||
static PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
|
||||
@ -474,6 +479,7 @@ public class ApiDBUtils {
|
||||
@Inject private ImageStoreJoinDao imageStoreJoinDao;
|
||||
@Inject private AccountJoinDao accountJoinDao;
|
||||
@Inject private AsyncJobJoinDao jobJoinDao;
|
||||
@Inject private TemplateJoinDao templateJoinDao;
|
||||
|
||||
@Inject private PhysicalNetworkTrafficTypeDao physicalNetworkTrafficTypeDao;
|
||||
@Inject private PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao;
|
||||
@ -575,6 +581,7 @@ public class ApiDBUtils {
|
||||
_imageStoreJoinDao = imageStoreJoinDao;
|
||||
_accountJoinDao = accountJoinDao;
|
||||
_jobJoinDao = jobJoinDao;
|
||||
_templateJoinDao = templateJoinDao;
|
||||
|
||||
_physicalNetworkTrafficTypeDao = physicalNetworkTrafficTypeDao;
|
||||
_physicalNetworkServiceProviderDao = physicalNetworkServiceProviderDao;
|
||||
@ -1606,4 +1613,33 @@ public class ApiDBUtils {
|
||||
public static List<NicSecondaryIpVO> findNicSecondaryIps(long nicId) {
|
||||
return _nicSecondaryIpDao.listByNicId(nicId);
|
||||
}
|
||||
|
||||
|
||||
public static TemplateResponse newTemplateUpdateResponse(TemplateJoinVO vr) {
|
||||
return _templateJoinDao.newUpdateResponse(vr);
|
||||
}
|
||||
|
||||
|
||||
public static TemplateResponse newTemplateResponse(TemplateJoinVO vr) {
|
||||
return _templateJoinDao.newTemplateResponse(vr);
|
||||
}
|
||||
|
||||
|
||||
public static TemplateResponse newIsoResponse(TemplateJoinVO vr) {
|
||||
return _templateJoinDao.newIsoResponse(vr);
|
||||
}
|
||||
|
||||
public static TemplateResponse fillTemplateDetails(TemplateResponse vrData, TemplateJoinVO vr){
|
||||
return _templateJoinDao.setTemplateResponse(vrData, vr);
|
||||
}
|
||||
|
||||
public static List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate vr){
|
||||
return _templateJoinDao.newTemplateView(vr);
|
||||
}
|
||||
|
||||
|
||||
public static List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate vr, long zoneId, boolean readyOnly){
|
||||
return _templateJoinDao.newTemplateView(vr, zoneId, readyOnly);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -16,9 +16,13 @@
|
||||
// under the License.
|
||||
package com.cloud.api.query;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -27,6 +31,7 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
|
||||
@ -35,6 +40,7 @@ import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
|
||||
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
|
||||
import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
|
||||
@ -42,6 +48,7 @@ import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
|
||||
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
|
||||
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
|
||||
import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
|
||||
import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
|
||||
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
|
||||
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
|
||||
@ -62,6 +69,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
@ -85,6 +93,7 @@ import com.cloud.api.query.dao.ResourceTagJoinDao;
|
||||
import com.cloud.api.query.dao.SecurityGroupJoinDao;
|
||||
import com.cloud.api.query.dao.ServiceOfferingJoinDao;
|
||||
import com.cloud.api.query.dao.StoragePoolJoinDao;
|
||||
import com.cloud.api.query.dao.TemplateJoinDao;
|
||||
import com.cloud.api.query.dao.UserAccountJoinDao;
|
||||
import com.cloud.api.query.dao.UserVmJoinDao;
|
||||
import com.cloud.api.query.dao.VolumeJoinDao;
|
||||
@ -104,6 +113,7 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.api.query.vo.SecurityGroupJoinVO;
|
||||
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
|
||||
import com.cloud.api.query.vo.StoragePoolJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.api.query.vo.UserAccountJoinVO;
|
||||
import com.cloud.api.query.vo.UserVmJoinVO;
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
@ -127,12 +137,20 @@ import com.cloud.projects.Project;
|
||||
import com.cloud.projects.ProjectManager;
|
||||
import com.cloud.projects.dao.ProjectAccountDao;
|
||||
import com.cloud.projects.dao.ProjectDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.server.Criteria;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.ImageStore;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
@ -146,6 +164,7 @@ import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
@ -255,6 +274,15 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
@Inject
|
||||
private HighAvailabilityManager _haMgr;
|
||||
|
||||
@Inject
|
||||
private VMTemplateDao _templateDao;
|
||||
|
||||
@Inject
|
||||
private TemplateJoinDao _templateJoinDao;
|
||||
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.api.query.QueryService#searchForUsers(org.apache.cloudstack.api.command.admin.user.ListUsersCmd)
|
||||
*/
|
||||
@ -2419,5 +2447,298 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListResponse<TemplateResponse> listTemplates(ListTemplatesCmd cmd) {
|
||||
Pair<List<TemplateJoinVO>, Integer> result = searchForTemplatesInternal(cmd);
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
|
||||
List<TemplateResponse> templateResponses = ViewResponseHelper.createTemplateResponse(result.first().toArray(new TemplateJoinVO[result.first().size()]));
|
||||
response.setResponses(templateResponses, result.second());
|
||||
return response;
|
||||
}
|
||||
|
||||
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTemplatesCmd cmd) {
|
||||
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
|
||||
Long id = cmd.getId();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
boolean listAll = false;
|
||||
if (templateFilter != null && templateFilter == TemplateFilter.all) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
|
||||
}
|
||||
listAll = true;
|
||||
}
|
||||
|
||||
List<Long> permittedAccountIds = new ArrayList<Long>();
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject,
|
||||
listAll, false);
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
List<Account> permittedAccounts = new ArrayList<Account>();
|
||||
for (Long accountId : permittedAccountIds) {
|
||||
permittedAccounts.add(_accountMgr.getAccount(accountId));
|
||||
}
|
||||
|
||||
boolean showDomr = ((templateFilter != TemplateFilter.selfexecutable) && (templateFilter != TemplateFilter.featured));
|
||||
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
|
||||
|
||||
return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(),
|
||||
cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags);
|
||||
}
|
||||
|
||||
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso,
|
||||
Boolean bootable, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady,
|
||||
List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
|
||||
VMTemplateVO template = null;
|
||||
|
||||
// verify templateId parameter
|
||||
if (templateId != null) {
|
||||
template = _templateDao.findById(templateId);
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid template ID.");
|
||||
}// If ISO requested then it should be ISO.
|
||||
if (isIso && template.getFormat() != ImageFormat.ISO) {
|
||||
s_logger.error("Template Id " + templateId + " is not an ISO");
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Specified Template Id is not an ISO");
|
||||
ex.addProxyObject(template, templateId, "templateId");
|
||||
throw ex;
|
||||
}// If ISO not requested then it shouldn't be an ISO.
|
||||
if (!isIso && template.getFormat() == ImageFormat.ISO) {
|
||||
s_logger.error("Incorrect format of the template id " + templateId);
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException("Incorrect format " + template.getFormat()
|
||||
+ " of the specified template id");
|
||||
ex.addProxyObject(template, templateId, "templateId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
// if template is not public, perform permission check here
|
||||
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
Account owner = _accountMgr.getAccount(template.getAccountId());
|
||||
_accountMgr.checkAccess(caller, null, true, owner);
|
||||
}
|
||||
}
|
||||
|
||||
DomainVO domain = null;
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
domain = _domainDao.findById(permittedAccounts.get(0).getDomainId());
|
||||
} else {
|
||||
domain = _domainDao.findById(DomainVO.ROOT_DOMAIN);
|
||||
}
|
||||
|
||||
List<HypervisorType> hypers = null;
|
||||
if (!isIso) {
|
||||
hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
|
||||
}
|
||||
|
||||
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
|
||||
isAscending = (isAscending == null ? true : isAscending);
|
||||
Filter searchFilter = new Filter(TemplateJoinVO.class, "sort_key", isAscending, startIndex, pageSize);
|
||||
SearchCriteria<TemplateJoinVO> sc = _templateJoinDao.createSearchCriteria();
|
||||
|
||||
// add criteria for project or not
|
||||
if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
|
||||
sc.addAnd("accountType", SearchCriteria.Op.NEQ, Account.ACCOUNT_TYPE_PROJECT);
|
||||
} else if (listProjectResourcesCriteria == ListProjectResourcesCriteria.ListProjectResourcesOnly){
|
||||
sc.addAnd("accountType", SearchCriteria.Op.EQ, Account.ACCOUNT_TYPE_PROJECT);
|
||||
}
|
||||
|
||||
// add criteria for domain path in case of domain admin
|
||||
if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) &&
|
||||
(caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
|
||||
sc.addAnd("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%");
|
||||
}
|
||||
|
||||
List<Long> relatedDomainIds = new ArrayList<Long>();
|
||||
List<Long> permittedAccountIds = new ArrayList<Long>();
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
for (Account account : permittedAccounts) {
|
||||
permittedAccountIds.add(account.getId());
|
||||
DomainVO accountDomain = _domainDao.findById(account.getDomainId());
|
||||
|
||||
// get all parent domain ID's all the way till root domain
|
||||
DomainVO domainTreeNode = accountDomain;
|
||||
relatedDomainIds.add(domainTreeNode.getId());
|
||||
while (domainTreeNode.getParent() != null ){
|
||||
domainTreeNode = _domainDao.findById(domainTreeNode.getParent());
|
||||
relatedDomainIds.add(domainTreeNode.getId());
|
||||
}
|
||||
|
||||
// get all child domain ID's
|
||||
if (_accountMgr.isAdmin(account.getType()) ) {
|
||||
List<DomainVO> allChildDomains = _domainDao.findAllChildren(accountDomain.getPath(), accountDomain.getId());
|
||||
for (DomainVO childDomain : allChildDomains) {
|
||||
relatedDomainIds.add(childDomain.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add hypervisor criteria
|
||||
if ( !hypers.isEmpty()){
|
||||
String[] relatedHypers = new String[hypers.size()];
|
||||
for (int i = 0; i < hypers.size(); i++){
|
||||
relatedHypers[i] = hypers.get(i).toString();
|
||||
}
|
||||
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
|
||||
}
|
||||
|
||||
// control different template filters
|
||||
if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) {
|
||||
sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true);
|
||||
if ( templateFilter == TemplateFilter.featured){
|
||||
sc.addAnd("featured", SearchCriteria.Op.EQ, true);
|
||||
}
|
||||
else{
|
||||
sc.addAnd("featured", SearchCriteria.Op.EQ, false);
|
||||
}
|
||||
if (!permittedAccounts.isEmpty()) {
|
||||
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
||||
scc.addOr("domainId", SearchCriteria.Op.IN, relatedDomainIds.toArray());
|
||||
scc.addOr("domainId", SearchCriteria.Op.NULL);
|
||||
sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
|
||||
|
||||
if (!_accountMgr.isAdmin(caller.getType())){
|
||||
// for non-root users, we should only show featured and community templates that they can see
|
||||
sc.addAnd("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
|
||||
}
|
||||
}
|
||||
} else if (templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable ) {
|
||||
if ( !permittedAccounts.isEmpty()){
|
||||
sc.addAnd("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
|
||||
}
|
||||
} else if (templateFilter == TemplateFilter.sharedexecutable || templateFilter == TemplateFilter.shared ) {
|
||||
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
||||
scc.addOr("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
|
||||
scc.addOr("sharedAccountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
|
||||
sc.addAnd("accountId", SearchCriteria.Op.SC, scc);
|
||||
} else if (templateFilter == TemplateFilter.executable ) {
|
||||
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
||||
scc.addOr("publicTemplate", SearchCriteria.Op.EQ, true);
|
||||
if ( !permittedAccounts.isEmpty()){
|
||||
scc.addOr("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
|
||||
}
|
||||
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
|
||||
}
|
||||
|
||||
// add tags criteria
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
||||
int count = 0;
|
||||
for (String key : tags.keySet()) {
|
||||
SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria();
|
||||
scTag.addAnd("tagKey", SearchCriteria.Op.EQ, key);
|
||||
scTag.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key));
|
||||
if ( isIso){
|
||||
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, TaggedResourceType.ISO);
|
||||
} else {
|
||||
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, TaggedResourceType.Template);
|
||||
}
|
||||
scc.addOr("tagKey", SearchCriteria.Op.SC, scTag);
|
||||
count++;
|
||||
}
|
||||
sc.addAnd("tagKey", SearchCriteria.Op.SC, scc);
|
||||
}
|
||||
|
||||
// other criteria
|
||||
if (keyword != null) {
|
||||
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
} else if (name != null) {
|
||||
sc.addAnd("name", SearchCriteria.Op.EQ, name);
|
||||
}
|
||||
|
||||
if (isIso) {
|
||||
sc.addAnd("format", SearchCriteria.Op.EQ, "ISO");
|
||||
|
||||
} else {
|
||||
sc.addAnd("format", SearchCriteria.Op.NEQ, "ISO");
|
||||
}
|
||||
|
||||
if (!hyperType.equals(HypervisorType.None)) {
|
||||
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType);
|
||||
}
|
||||
|
||||
if (bootable != null) {
|
||||
sc.addAnd("bootable", SearchCriteria.Op.EQ, bootable);
|
||||
}
|
||||
|
||||
if (onlyReady){
|
||||
sc.addAnd("downlaadState", SearchCriteria.Op.EQ, Status.DOWNLOADED);
|
||||
sc.addAnd("destroyed", SearchCriteria.Op.EQ, false);
|
||||
}
|
||||
|
||||
if (zoneId != null){
|
||||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
|
||||
}
|
||||
|
||||
if (!showDomr){
|
||||
// excluding system template
|
||||
sc.addAnd("type", SearchCriteria.Op.NEQ, Storage.TemplateType.SYSTEM);
|
||||
}
|
||||
|
||||
// search unique templates and find details by Ids
|
||||
Pair<List<TemplateJoinVO>, Integer> uniqueTmplPair = _templateJoinDao.searchAndCount(sc, searchFilter);
|
||||
Integer count = uniqueTmplPair.second();
|
||||
if (count.intValue() == 0) {
|
||||
// empty result
|
||||
return uniqueTmplPair;
|
||||
}
|
||||
List<TemplateJoinVO> uniqueTmpls = uniqueTmplPair.first();
|
||||
Long[] vrIds = new Long[uniqueTmpls.size()];
|
||||
int i = 0;
|
||||
for (TemplateJoinVO v : uniqueTmpls) {
|
||||
vrIds[i++] = v.getId();
|
||||
}
|
||||
List<TemplateJoinVO> vrs = _templateJoinDao.searchByIds(vrIds);
|
||||
return new Pair<List<TemplateJoinVO>, Integer>(vrs, count);
|
||||
|
||||
//TODO: revisit the special logic for iso search in VMTemplateDaoImpl.searchForTemplates and understand why we need to
|
||||
//specially handle ISO. The original logic is very twisted and no idea about what the code was doing.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd) {
|
||||
Pair<List<TemplateJoinVO>, Integer> result = searchForIsosInternal(cmd);
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
|
||||
List<TemplateResponse> templateResponses = ViewResponseHelper.createIsoResponse(result.first().toArray(new TemplateJoinVO[result.first().size()]));
|
||||
response.setResponses(templateResponses, result.second());
|
||||
return response;
|
||||
}
|
||||
|
||||
private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cmd) {
|
||||
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
|
||||
Long id = cmd.getId();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
boolean listAll = false;
|
||||
if (isoFilter != null && isoFilter == TemplateFilter.all) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
|
||||
}
|
||||
listAll = true;
|
||||
}
|
||||
|
||||
List<Long> permittedAccountIds = new ArrayList<Long>();
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject,
|
||||
listAll, false);
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
List<Account> permittedAccounts = new ArrayList<Account>();
|
||||
for (Long accountId : permittedAccountIds) {
|
||||
permittedAccounts.add(_accountMgr.getAccount(accountId));
|
||||
}
|
||||
|
||||
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
|
||||
|
||||
return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(), cmd.getPageSizeVal(),
|
||||
cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller,
|
||||
listProjectResourcesCriteria, tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
@ -61,6 +62,7 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.api.query.vo.SecurityGroupJoinVO;
|
||||
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
|
||||
import com.cloud.api.query.vo.StoragePoolJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.api.query.vo.UserAccountJoinVO;
|
||||
import com.cloud.api.query.vo.UserVmJoinVO;
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
@ -323,4 +325,55 @@ public class ViewResponseHelper {
|
||||
}
|
||||
return respList;
|
||||
}
|
||||
|
||||
public static List<TemplateResponse> createTemplateResponse(TemplateJoinVO... templates) {
|
||||
Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
|
||||
for (TemplateJoinVO vr : templates) {
|
||||
TemplateResponse vrData = vrDataList.get(vr.getId());
|
||||
if ( vrData == null ){
|
||||
// first time encountering this volume
|
||||
vrData = ApiDBUtils.newTemplateResponse(vr);
|
||||
}
|
||||
else{
|
||||
// update tags
|
||||
vrData = ApiDBUtils.fillTemplateDetails(vrData, vr);
|
||||
}
|
||||
vrDataList.put(vr.getId(), vrData);
|
||||
}
|
||||
return new ArrayList<TemplateResponse>(vrDataList.values());
|
||||
}
|
||||
|
||||
public static List<TemplateResponse> createTemplateUpdateResponse(TemplateJoinVO... templates) {
|
||||
Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
|
||||
for (TemplateJoinVO vr : templates) {
|
||||
TemplateResponse vrData = vrDataList.get(vr.getId());
|
||||
if ( vrData == null ){
|
||||
// first time encountering this volume
|
||||
vrData = ApiDBUtils.newTemplateUpdateResponse(vr);
|
||||
}
|
||||
else{
|
||||
// update tags
|
||||
vrData = ApiDBUtils.fillTemplateDetails(vrData, vr);
|
||||
}
|
||||
vrDataList.put(vr.getId(), vrData);
|
||||
}
|
||||
return new ArrayList<TemplateResponse>(vrDataList.values());
|
||||
}
|
||||
|
||||
public static List<TemplateResponse> createIsoResponse(TemplateJoinVO... templates) {
|
||||
Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
|
||||
for (TemplateJoinVO vr : templates) {
|
||||
TemplateResponse vrData = vrDataList.get(vr.getId());
|
||||
if ( vrData == null ){
|
||||
// first time encountering this volume
|
||||
vrData = ApiDBUtils.newIsoResponse(vr);
|
||||
}
|
||||
else{
|
||||
// update tags
|
||||
vrData = ApiDBUtils.fillTemplateDetails(vrData, vr);
|
||||
}
|
||||
vrDataList.put(vr.getId(), vrData);
|
||||
}
|
||||
return new ArrayList<TemplateResponse>(vrDataList.values());
|
||||
}
|
||||
}
|
||||
|
||||
42
server/src/com/cloud/api/query/dao/TemplateJoinDao.java
Normal file
42
server/src/com/cloud/api/query/dao/TemplateJoinDao.java
Normal file
@ -0,0 +1,42 @@
|
||||
// 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.query.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface TemplateJoinDao extends GenericDao<TemplateJoinVO, Long> {
|
||||
|
||||
TemplateResponse newTemplateResponse(TemplateJoinVO tmpl);
|
||||
|
||||
TemplateResponse newIsoResponse(TemplateJoinVO tmpl);
|
||||
|
||||
TemplateResponse newUpdateResponse(TemplateJoinVO tmpl);
|
||||
|
||||
TemplateResponse setTemplateResponse(TemplateResponse tmplData, TemplateJoinVO tmpl);
|
||||
|
||||
List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate tmpl);
|
||||
|
||||
List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate tmpl, long zoneId, boolean readyOnly);
|
||||
|
||||
List<TemplateJoinVO> searchByIds(Long... ids);
|
||||
|
||||
}
|
||||
441
server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
Normal file
441
server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
Normal file
@ -0,0 +1,441 @@
|
||||
// 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.query.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateZoneResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
||||
|
||||
@Component
|
||||
@Local(value={TemplateJoinDao.class})
|
||||
public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> implements TemplateJoinDao {
|
||||
|
||||
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(TemplateJoinDaoImpl.class);
|
||||
|
||||
@Inject
|
||||
private ConfigurationDao _configDao;
|
||||
|
||||
private final SearchBuilder<TemplateJoinVO> tmpltSearch;
|
||||
|
||||
private final SearchBuilder<TemplateJoinVO> tmpltIdSearch;
|
||||
|
||||
private final SearchBuilder<TemplateJoinVO> tmpltZoneSearch;
|
||||
|
||||
|
||||
protected TemplateJoinDaoImpl() {
|
||||
|
||||
tmpltSearch = createSearchBuilder();
|
||||
tmpltSearch.and("idIN", tmpltSearch.entity().getId(), SearchCriteria.Op.IN);
|
||||
tmpltSearch.done();
|
||||
|
||||
tmpltIdSearch = createSearchBuilder();
|
||||
tmpltIdSearch.and("id", tmpltIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
tmpltIdSearch.done();
|
||||
|
||||
tmpltZoneSearch = createSearchBuilder();
|
||||
tmpltZoneSearch.and("id", tmpltZoneSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
tmpltZoneSearch.and("dataCenterId", tmpltZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
tmpltZoneSearch.and("downloadState", tmpltZoneSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
|
||||
tmpltZoneSearch.done();
|
||||
|
||||
// select distinct pair (template_id, zone_id)
|
||||
this._count = "select count(distinct id) from template_view WHERE ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateResponse newTemplateResponse(TemplateJoinVO template) {
|
||||
TemplateResponse templateResponse = new TemplateResponse();
|
||||
templateResponse.setId(template.getUuid());
|
||||
templateResponse.setName(template.getName());
|
||||
templateResponse.setDisplayText(template.getDisplayText());
|
||||
templateResponse.setPublic(template.isPublicTemplate());
|
||||
templateResponse.setCreated(template.getCreatedOnStore());
|
||||
templateResponse.setReady(template.getDownloadState() == Status.DOWNLOADED);
|
||||
templateResponse.setFeatured(template.isFeatured());
|
||||
templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
|
||||
templateResponse.setPasswordEnabled(template.isEnablePassword());
|
||||
templateResponse.setSshKeyEnabled(template.isEnableSshKey());
|
||||
templateResponse.setCrossZones(template.isCrossZones());
|
||||
templateResponse.setFormat(template.getFormat());
|
||||
if (template.getTemplateType() != null) {
|
||||
templateResponse.setTemplateType(template.getTemplateType().toString());
|
||||
}
|
||||
|
||||
templateResponse.setHypervisor(template.getHypervisorType().toString());
|
||||
|
||||
|
||||
templateResponse.setOsTypeId(template.getGuestOSUuid());
|
||||
templateResponse.setOsTypeName(template.getGuestOSName());
|
||||
|
||||
// populate owner.
|
||||
ApiResponseHelper.populateOwner(templateResponse, template);
|
||||
|
||||
// populate domain
|
||||
templateResponse.setDomainId(template.getDomainUuid());
|
||||
templateResponse.setDomainName(template.getDomainName());
|
||||
|
||||
|
||||
|
||||
boolean isAdmin = false;
|
||||
Account caller = UserContext.current().getCaller();
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
// If the user is an Admin, add the template download status
|
||||
if (isAdmin || caller.getId() == template.getAccountId()) {
|
||||
// add download status
|
||||
if (template.getDownloadState() != Status.DOWNLOADED) {
|
||||
String templateStatus = "Processing";
|
||||
if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
if (template.getDownloadPercent() == 100) {
|
||||
templateStatus = "Installing Template";
|
||||
} else {
|
||||
templateStatus = template.getDownloadPercent() + "% Downloaded";
|
||||
}
|
||||
} else {
|
||||
templateStatus = template.getErrorString();
|
||||
}
|
||||
templateResponse.setStatus(templateStatus);
|
||||
} else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
|
||||
templateResponse.setStatus("Download Complete");
|
||||
} else {
|
||||
templateResponse.setStatus("Successfully Installed");
|
||||
}
|
||||
}
|
||||
|
||||
Long templateSize = template.getSize();
|
||||
if (templateSize > 0) {
|
||||
templateResponse.setSize(templateSize);
|
||||
}
|
||||
|
||||
templateResponse.setChecksum(template.getChecksum());
|
||||
if (template.getSourceTemplateId() != null) {
|
||||
templateResponse.setSourceTemplateId(template.getSourceTemplateUuid());
|
||||
}
|
||||
templateResponse.setTemplateTag(template.getTemplateTag());
|
||||
|
||||
// set template zone information
|
||||
if (template.getDataCenterId() > 0 ){
|
||||
TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(), template.getDataCenterName());
|
||||
templateResponse.addZone(tmplZoneResp);
|
||||
// set the first found associated zone directly in TemplateResponse
|
||||
templateResponse.setZoneId(template.getDataCenterUuid());
|
||||
templateResponse.setZoneName(template.getDataCenterName());
|
||||
}
|
||||
|
||||
// set details map
|
||||
if (template.getDetailName() != null){
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
details.put(template.getDetailName(), template.getDetailValue());
|
||||
templateResponse.setDetails(details);
|
||||
}
|
||||
|
||||
// update tag information
|
||||
long tag_id = template.getTagId();
|
||||
if (tag_id > 0) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if ( vtag != null ){
|
||||
templateResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
templateResponse.setObjectName("template");
|
||||
return templateResponse;
|
||||
}
|
||||
|
||||
|
||||
//TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
|
||||
// compared to listTemplates and listIsos.
|
||||
@Override
|
||||
public TemplateResponse newUpdateResponse(TemplateJoinVO result) {
|
||||
TemplateResponse response = new TemplateResponse();
|
||||
response.setId(result.getUuid());
|
||||
response.setName(result.getName());
|
||||
response.setDisplayText(result.getDisplayText());
|
||||
response.setPublic(result.isPublicTemplate());
|
||||
response.setCreated(result.getCreated());
|
||||
response.setFormat(result.getFormat());
|
||||
response.setOsTypeId(result.getGuestOSUuid());
|
||||
response.setOsTypeName(result.getGuestOSName());
|
||||
response.setBootable(result.isBootable());
|
||||
response.setHypervisor(result.getHypervisorType().toString());
|
||||
|
||||
// populate owner.
|
||||
ApiResponseHelper.populateOwner(response, result);
|
||||
|
||||
// populate domain
|
||||
response.setDomainId(result.getDomainUuid());
|
||||
response.setDomainName(result.getDomainName());
|
||||
|
||||
// set details map
|
||||
if (result.getDetailName() != null) {
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
details.put(result.getDetailName(), result.getDetailValue());
|
||||
response.setDetails(details);
|
||||
}
|
||||
|
||||
// update tag information
|
||||
long tag_id = result.getTagId();
|
||||
if (tag_id > 0) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if (vtag != null) {
|
||||
response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
}
|
||||
}
|
||||
|
||||
response.setObjectName("iso");
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateResponse setTemplateResponse(TemplateResponse templateResponse, TemplateJoinVO template) {
|
||||
|
||||
// update template zone information
|
||||
if (template.getDataCenterId() > 0 ){
|
||||
TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(), template.getDataCenterName());
|
||||
templateResponse.addZone(tmplZoneResp);
|
||||
if (templateResponse.getZoneId() == null) {
|
||||
// set the first found associated zone directly in
|
||||
// TemplateResponse
|
||||
templateResponse.setZoneId(template.getDataCenterUuid());
|
||||
templateResponse.setZoneName(template.getDataCenterName());
|
||||
}
|
||||
}
|
||||
|
||||
// update details map
|
||||
if (template.getDetailName() != null){
|
||||
Map<String, String> details = templateResponse.getDetails();
|
||||
if ( details == null ){
|
||||
details = new HashMap<String, String>();
|
||||
}
|
||||
details.put(template.getDetailName(), template.getDetailValue());
|
||||
templateResponse.setDetails(details);
|
||||
}
|
||||
|
||||
// update tag information
|
||||
long tag_id = template.getTagId();
|
||||
if (tag_id > 0) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if ( vtag != null ){
|
||||
templateResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
}
|
||||
}
|
||||
|
||||
return templateResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateResponse newIsoResponse(TemplateJoinVO iso) {
|
||||
|
||||
TemplateResponse isoResponse = new TemplateResponse();
|
||||
isoResponse.setId(iso.getUuid());
|
||||
isoResponse.setName(iso.getName());
|
||||
isoResponse.setDisplayText(iso.getDisplayText());
|
||||
isoResponse.setPublic(iso.isPublicTemplate());
|
||||
isoResponse.setExtractable(iso.isExtractable() && !(iso.getTemplateType() == TemplateType.PERHOST));
|
||||
isoResponse.setCreated(iso.getCreatedOnStore());
|
||||
isoResponse.setReady(iso.getDownloadState() == Status.DOWNLOADED);
|
||||
isoResponse.setBootable(iso.isBootable());
|
||||
isoResponse.setFeatured(iso.isFeatured());
|
||||
isoResponse.setCrossZones(iso.isCrossZones());
|
||||
isoResponse.setPublic(iso.isPublicTemplate());
|
||||
isoResponse.setChecksum(iso.getChecksum());
|
||||
|
||||
isoResponse.setOsTypeId(iso.getGuestOSUuid());
|
||||
isoResponse.setOsTypeName(iso.getGuestOSName());
|
||||
|
||||
// populate owner.
|
||||
ApiResponseHelper.populateOwner(isoResponse, iso);
|
||||
|
||||
// populate domain
|
||||
isoResponse.setDomainId(iso.getDomainUuid());
|
||||
isoResponse.setDomainName(iso.getDomainName());
|
||||
|
||||
// set template zone information
|
||||
if (iso.getDataCenterId() > 0 ){
|
||||
TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(iso.getDataCenterUuid(), iso.getDataCenterName());
|
||||
isoResponse.addZone(tmplZoneResp);
|
||||
// set the first found associated zone directly in TemplateResponse
|
||||
isoResponse.setZoneId(iso.getDataCenterUuid());
|
||||
isoResponse.setZoneName(iso.getDataCenterName());
|
||||
}
|
||||
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
boolean isAdmin = false;
|
||||
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
|
||||
// If the user is an admin, add the template download status
|
||||
if (isAdmin || caller.getId() == iso.getAccountId()) {
|
||||
// add download status
|
||||
if (iso.getDownloadState() != Status.DOWNLOADED) {
|
||||
String isoStatus = "Processing";
|
||||
if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
|
||||
isoStatus = "Download Complete";
|
||||
} else if (iso.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
if (iso.getDownloadPercent() == 100) {
|
||||
isoStatus = "Installing ISO";
|
||||
} else {
|
||||
isoStatus = iso.getDownloadPercent() + "% Downloaded";
|
||||
}
|
||||
} else {
|
||||
isoStatus = iso.getErrorString();
|
||||
}
|
||||
isoResponse.setStatus(isoStatus);
|
||||
} else {
|
||||
isoResponse.setStatus("Successfully Installed");
|
||||
}
|
||||
}
|
||||
|
||||
Long isoSize = iso.getSize();
|
||||
if (isoSize > 0) {
|
||||
isoResponse.setSize(isoSize);
|
||||
}
|
||||
|
||||
// update tag information
|
||||
long tag_id = iso.getTagId();
|
||||
if (tag_id > 0) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if ( vtag != null ){
|
||||
isoResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
}
|
||||
}
|
||||
|
||||
isoResponse.setObjectName("iso");
|
||||
return isoResponse;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate template) {
|
||||
SearchCriteria<TemplateJoinVO> sc = tmpltIdSearch.create();
|
||||
sc.setParameters("id", template.getId());
|
||||
return searchIncludingRemoved(sc, null, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate template, long zoneId, boolean readyOnly) {
|
||||
SearchCriteria<TemplateJoinVO> sc = tmpltZoneSearch.create();
|
||||
sc.setParameters("id", template.getId());
|
||||
sc.setParameters("dataCenterId", zoneId);
|
||||
if ( readyOnly ){
|
||||
sc.setParameters("downloadState", VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
}
|
||||
return searchIncludingRemoved(sc, null, null, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<TemplateJoinVO> searchByIds(Long... tmplIds) {
|
||||
// set detail batch query size
|
||||
int DETAILS_BATCH_SIZE = 2000;
|
||||
String batchCfg = _configDao.getValue("detail.batch.query.size");
|
||||
if ( batchCfg != null ){
|
||||
DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
|
||||
}
|
||||
// query details by batches
|
||||
List<TemplateJoinVO> uvList = new ArrayList<TemplateJoinVO>();
|
||||
// query details by batches
|
||||
int curr_index = 0;
|
||||
if ( tmplIds.length > DETAILS_BATCH_SIZE ){
|
||||
while ( (curr_index + DETAILS_BATCH_SIZE ) <= tmplIds.length ) {
|
||||
Long[] ids = new Long[DETAILS_BATCH_SIZE];
|
||||
for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
|
||||
ids[k] = tmplIds[j];
|
||||
}
|
||||
SearchCriteria<TemplateJoinVO> sc = tmpltSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<TemplateJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
|
||||
if (vms != null) {
|
||||
uvList.addAll(vms);
|
||||
}
|
||||
curr_index += DETAILS_BATCH_SIZE;
|
||||
}
|
||||
}
|
||||
if (curr_index < tmplIds.length) {
|
||||
int batch_size = (tmplIds.length - curr_index);
|
||||
// set the ids value
|
||||
Long[] ids = new Long[batch_size];
|
||||
for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
|
||||
ids[k] = tmplIds[j];
|
||||
}
|
||||
SearchCriteria<TemplateJoinVO> sc = tmpltSearch.create();
|
||||
sc.setParameters("idIN", ids);
|
||||
List<TemplateJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
|
||||
if (vms != null) {
|
||||
uvList.addAll(vms);
|
||||
}
|
||||
}
|
||||
return uvList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
1006
server/src/com/cloud/api/query/vo/TemplateJoinVO.java
Normal file
1006
server/src/com/cloud/api/query/vo/TemplateJoinVO.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -1112,70 +1112,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
return new Pair<List<? extends Configuration>, Integer>(result.first(), result.second());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
|
||||
boolean listAll = false;
|
||||
if (isoFilter != null && isoFilter == TemplateFilter.all) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
|
||||
}
|
||||
listAll = true;
|
||||
}
|
||||
List<Long> permittedAccountIds = new ArrayList<Long>();
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, cmd.getId(), cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds,
|
||||
domainIdRecursiveListProject, listAll, false);
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
|
||||
List<Account> permittedAccounts = new ArrayList<Account>();
|
||||
for (Long accountId : permittedAccountIds) {
|
||||
permittedAccounts.add(_accountMgr.getAccount(accountId));
|
||||
}
|
||||
|
||||
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
|
||||
return listTemplates(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(), cmd.getPageSizeVal(),
|
||||
cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller,
|
||||
listProjectResourcesCriteria, tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
|
||||
Long id = cmd.getId();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
boolean listAll = false;
|
||||
if (templateFilter != null && templateFilter == TemplateFilter.all) {
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
|
||||
}
|
||||
listAll = true;
|
||||
}
|
||||
|
||||
List<Long> permittedAccountIds = new ArrayList<Long>();
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject,
|
||||
listAll, false);
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
List<Account> permittedAccounts = new ArrayList<Account>();
|
||||
for (Long accountId : permittedAccountIds) {
|
||||
permittedAccounts.add(_accountMgr.getAccount(accountId));
|
||||
}
|
||||
|
||||
boolean showDomr = ((templateFilter != TemplateFilter.selfexecutable) && (templateFilter != TemplateFilter.featured));
|
||||
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
|
||||
|
||||
return listTemplates(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(),
|
||||
cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags);
|
||||
}
|
||||
|
||||
/* TODO: this method should go away. Keep here just in case that our latest refactoring using template_store_ref missed anything
|
||||
* in handling Swift or S3.
|
||||
private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso,
|
||||
Boolean bootable, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady,
|
||||
List<Account> permittedAccounts, Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags) {
|
||||
@ -1274,7 +1214,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
|
||||
return templateZonePairSet;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,11 +37,11 @@ import com.cloud.utils.fsm.StateDao;
|
||||
* Data Access Object for vm_templates table
|
||||
*/
|
||||
public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<TemplateState, TemplateEvent, VMTemplateVO> {
|
||||
|
||||
|
||||
|
||||
|
||||
public List<VMTemplateVO> listByPublic();
|
||||
public VMTemplateVO findByName(String templateName);
|
||||
public VMTemplateVO findByTemplateName(String templateName);
|
||||
public VMTemplateVO findByTemplateName(String templateName);
|
||||
|
||||
//public void update(VMTemplateVO template);
|
||||
|
||||
@ -53,11 +53,13 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
||||
public List<VMTemplateVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
|
||||
public List<VMTemplateVO> listReadyTemplates();
|
||||
public List<VMTemplateVO> listByAccountId(long accountId);
|
||||
|
||||
/* TODO: these routines should go away, the logic has been consolidated and refactored in QueryService
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
|
||||
List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
|
||||
HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags);
|
||||
|
||||
|
||||
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter,
|
||||
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
|
||||
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
|
||||
@ -65,10 +67,11 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
||||
public Set<Pair<Long, Long>> searchS3Templates(String name, String keyword, TemplateFilter templateFilter,
|
||||
boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
|
||||
Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags);
|
||||
*/
|
||||
|
||||
public long addTemplateToZone(VMTemplateVO tmplt, long zoneId);
|
||||
public List<VMTemplateVO> listAllInZone(long dataCenterId);
|
||||
|
||||
public List<VMTemplateVO> listAllInZone(long dataCenterId);
|
||||
|
||||
public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes);
|
||||
public List<VMTemplateVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String, String> tags);
|
||||
public List<VMTemplateVO> userIsoSearch(boolean listRemoved);
|
||||
@ -78,7 +81,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
||||
VMTemplateVO findRoutingTemplate(HypervisorType type);
|
||||
List<Long> listPrivateTemplatesByHost(Long hostId);
|
||||
public Long countTemplatesForAccount(long accountId);
|
||||
|
||||
|
||||
List<VMTemplateVO> findTemplatesToSyncToS3();
|
||||
|
||||
}
|
||||
|
||||
@ -16,25 +16,17 @@
|
||||
// under the License.
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import static com.cloud.utils.StringUtils.join;
|
||||
import static com.cloud.utils.db.DbUtil.closeResources;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -42,25 +34,19 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.projects.Project.ListProjectResourcesCriteria;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.tags.ResourceTagVO;
|
||||
import com.cloud.tags.dao.ResourceTagDao;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
@ -92,6 +78,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
DomainDao _domainDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
|
||||
/* TODO: these direct sql should go away with recent QueryService refactoring to handle listTemplatesCmd. Keep here just for
|
||||
* potential bug reference.
|
||||
private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
|
||||
@ -103,6 +92,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
|
||||
private final String SELECT_TEMPLATE_S3_REF = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, "
|
||||
+ "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
*/
|
||||
|
||||
private static final String SELECT_S3_CANDIDATE_TEMPLATES = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, " +
|
||||
"t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, t.checksum, t.display_text, " +
|
||||
@ -397,6 +387,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
return routerTmpltName;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Set<Pair<Long, Long>> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain,
|
||||
Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller, Map<String, String> tags) {
|
||||
@ -538,7 +529,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
/* Use LinkedHashSet here to guarantee iteration order */
|
||||
// Use LinkedHashSet here to guarantee iteration order
|
||||
Set<Pair<Long, Long>> templateZonePairList = new LinkedHashSet<Pair<Long, Long>>();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
@ -751,7 +742,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
|
||||
return templateZonePairList;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) {
|
||||
String sql = "";
|
||||
if (keyword != null) {
|
||||
@ -811,6 +804,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ -873,7 +867,8 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
}
|
||||
|
||||
public VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType) {
|
||||
@Override
|
||||
public VMTemplateVO findSystemVMTemplate(long zoneId, HypervisorType hType) {
|
||||
SearchCriteria<VMTemplateVO> sc = tmpltTypeHyperSearch.create();
|
||||
sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
|
||||
sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing);
|
||||
@ -938,18 +933,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isAdmin(short accountType) {
|
||||
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) ||
|
||||
(accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) ||
|
||||
(accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) ||
|
||||
(accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> findTemplatesToSyncToS3() {
|
||||
return executeList(SELECT_S3_CANDIDATE_TEMPLATES, new Object[] {});
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Set<Pair<Long, Long>> searchS3Templates(final String name,
|
||||
final String keyword, final TemplateFilter templateFilter,
|
||||
@ -1083,6 +1074,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
|
||||
return templateZonePairList;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean updateState(TemplateState currentState, TemplateEvent event,
|
||||
|
||||
@ -2118,6 +2118,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
@Override
|
||||
public VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId,
|
||||
boolean readyOnly) {
|
||||
// readyOnly flag is not used at all
|
||||
List<HostVO> hosts = _ssvmMgr
|
||||
.listSecondaryStorageHostsInOneZone(zoneId);
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
|
||||
@ -519,3 +519,98 @@ INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type,
|
||||
VALUES (10, 'routing-10', 'SystemVM Template (LXC)', 0, now(), 'SYSTEM', 0, 64, 1, 'http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2', '2755de1f9ef2ce4d6f2bee2efbb4da92', 0, 'SystemVM Template (LXC)', 'QCOW2', 15, 0, 1, 'LXC');
|
||||
|
||||
-- END: support for LXC
|
||||
|
||||
DROP VIEW IF EXISTS `cloud`.`template_view`;
|
||||
CREATE VIEW `cloud`.`template_view` AS
|
||||
select
|
||||
vm_template.id,
|
||||
vm_template.uuid,
|
||||
vm_template.unique_name,
|
||||
vm_template.name,
|
||||
vm_template.public,
|
||||
vm_template.featured,
|
||||
vm_template.type,
|
||||
vm_template.hvm,
|
||||
vm_template.bits,
|
||||
vm_template.url,
|
||||
vm_template.format,
|
||||
vm_template.created,
|
||||
vm_template.checksum,
|
||||
vm_template.display_text,
|
||||
vm_template.enable_password,
|
||||
vm_template.guest_os_id,
|
||||
guest_os.uuid guest_os_uuid,
|
||||
guest_os.display_name guest_os_name,
|
||||
vm_template.bootable,
|
||||
vm_template.prepopulate,
|
||||
vm_template.cross_zones,
|
||||
vm_template.hypervisor_type,
|
||||
vm_template.extractable,
|
||||
vm_template.template_tag,
|
||||
vm_template.sort_key,
|
||||
source_template.id source_template_id,
|
||||
source_template.uuid source_template_uuid,
|
||||
account.id account_id,
|
||||
account.uuid account_uuid,
|
||||
account.account_name account_name,
|
||||
account.type account_type,
|
||||
domain.id domain_id,
|
||||
domain.uuid domain_uuid,
|
||||
domain.name domain_name,
|
||||
domain.path domain_path,
|
||||
projects.id project_id,
|
||||
projects.uuid project_uuid,
|
||||
projects.name project_name,
|
||||
data_center.id data_center_id,
|
||||
data_center.uuid data_center_uuid,
|
||||
data_center.name data_center_name,
|
||||
launch_permission.account_id lp_account_id,
|
||||
template_store_ref.download_state,
|
||||
template_store_ref.download_pct,
|
||||
template_store_ref.error_str,
|
||||
template_store_ref.size,
|
||||
template_store_ref.destroyed,
|
||||
template_store_ref.created created_on_store,
|
||||
vm_template_details.name detail_name,
|
||||
vm_template_details.value detail_value,
|
||||
resource_tags.id tag_id,
|
||||
resource_tags.uuid tag_uuid,
|
||||
resource_tags.key tag_key,
|
||||
resource_tags.value tag_value,
|
||||
resource_tags.domain_id tag_domain_id,
|
||||
resource_tags.account_id tag_account_id,
|
||||
resource_tags.resource_id tag_resource_id,
|
||||
resource_tags.resource_uuid tag_resource_uuid,
|
||||
resource_tags.resource_type tag_resource_type,
|
||||
resource_tags.customer tag_customer
|
||||
from
|
||||
`cloud`.`vm_template`
|
||||
inner join
|
||||
`cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id
|
||||
inner join
|
||||
`cloud`.`account` ON account.id = vm_template.account_id
|
||||
inner join
|
||||
`cloud`.`domain` ON domain.id = account.domain_id
|
||||
left join
|
||||
`cloud`.`projects` ON projects.project_account_id = account.id
|
||||
left join
|
||||
`cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id
|
||||
left join
|
||||
`cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id
|
||||
left join
|
||||
`cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id
|
||||
AND template_zone_ref.removed is null
|
||||
left join
|
||||
`cloud`.`data_center` ON template_zone_ref.zone_id = data_center.id
|
||||
left join
|
||||
`cloud`.`image_store` ON image_store.data_center_id = data_center.id OR image_store.scope = 'REGION'
|
||||
left join
|
||||
`cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id AND template_store_ref.store_id = image_store.id
|
||||
left join
|
||||
`cloud`.`launch_permission` ON launch_permission.template_id = vm_template.id
|
||||
left join
|
||||
`cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id
|
||||
and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO');
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user