Search in sources :

Example 46 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cosmic by MissionCriticalCloud.

the class UpdateTemplateCmd method execute.

@Override
public void execute() {
    final VirtualMachineTemplate result = _templateService.updateTemplate(this);
    if (result != null) {
        final TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
        response.setObjectName("template");
        // Template can be either USER or ROUTING type
        response.setTemplateType(result.getTemplateType().toString());
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 47 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cosmic by MissionCriticalCloud.

the class RegisterIsoCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
    final VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        final ListResponse<TemplateResponse> response = new ListResponse<>();
        final List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Restricted, template, zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register ISO");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 48 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cosmic by MissionCriticalCloud.

the class RequestTest method testDownload.

@Test
public void testDownload() {
    s_logger.info("Testing Download answer");
    final VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
    Mockito.when(template.getId()).thenReturn(1L);
    Mockito.when(template.getFormat()).thenReturn(ImageFormat.QCOW2);
    Mockito.when(template.getName()).thenReturn("templatename");
    Mockito.when(template.getTemplateType()).thenReturn(TemplateType.USER);
    Mockito.when(template.getDisplayText()).thenReturn("displayText");
    Mockito.when(template.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(template.getUrl()).thenReturn("url");
    final NfsTO nfs = new NfsTO("secUrl", DataStoreRole.Image);
    final TemplateObjectTO to = new TemplateObjectTO(template);
    to.setImageDataStore(nfs);
    final DownloadCommand cmd = new DownloadCommand(to, 30000000l);
    final Request req = new Request(1, 1, cmd, true);
    req.logD("Debug for Download");
    final DownloadAnswer answer = new DownloadAnswer("jobId", 50, "errorString", Status.ABANDONED, "filesystempath", "installpath", 10000000, 20000000, "chksum");
    final Response resp = new Response(req, answer);
    resp.logD("Debug for Download");
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(com.cloud.storage.command.DownloadCommand) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) Test(org.junit.Test)

Example 49 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cosmic by MissionCriticalCloud.

the class DownloadMonitorImpl method initiateTemplateDownload.

private void initiateTemplateDownload(final DataObject template, final AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    TemplateDataStoreVO vmTemplateStore = null;
    final DataStore store = template.getDataStore();
    vmTemplateStore = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
    if (vmTemplateStore == null) {
        vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri());
        vmTemplateStore.setDataStoreRole(store.getRole());
        vmTemplateStore = _vmTemplateStoreDao.persist(vmTemplateStore);
    } else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
        downloadJobExists = true;
    }
    final Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
    if (vmTemplateStore != null) {
        start();
        final VirtualMachineTemplate tmpl = _templateDao.findById(template.getId());
        DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (template.getTO()), maxTemplateSizeInBytes);
        dcmd.setProxy(getHttpProxy());
        if (downloadJobExists) {
            dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART);
        }
        if (vmTemplateStore.isCopy()) {
            dcmd.setCreds(TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd);
        }
        final EndPoint ep = _epSelector.select(template);
        if (ep == null) {
            final String errMsg = "There is no secondary storage VM for downloading template to image store " + store.getName();
            s_logger.warn(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        final DownloadListener dl = new DownloadListener(ep, store, template, _timer, this, dcmd, callback);
        // initialize those auto-wired field in download listener.
        ComponentContext.inject(dl);
        if (downloadJobExists) {
            // due to handling existing download job issues, we still keep
            // downloadState in template_store_ref to avoid big change in
            // DownloadListener to use
            // new ObjectInDataStore.State transition. TODO: fix this later
            // to be able to remove downloadState from template_store_ref.
            s_logger.info("found existing download job");
            dl.setCurrState(vmTemplateStore.getDownloadState());
        }
        try {
            ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
        } catch (final Exception e) {
            s_logger.warn("Unable to start /resume download of template " + template.getId() + " to " + store.getName(), e);
            dl.setDisconnected();
            dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(com.cloud.storage.command.DownloadCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadProgressCommand(com.cloud.storage.command.DownloadProgressCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 50 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cloudstack by apache.

the class DeployVMCmd method getDataDiskTemplateToDiskOfferingMap.

public Map<Long, DiskOffering> getDataDiskTemplateToDiskOfferingMap() {
    if (diskOfferingId != null && dataDiskTemplateToDiskOfferingList != null) {
        throw new InvalidParameterValueException("diskofferingid paramter can't be specified along with datadisktemplatetodiskofferinglist parameter");
    }
    if (MapUtils.isEmpty(dataDiskTemplateToDiskOfferingList)) {
        return new HashMap<Long, DiskOffering>();
    }
    HashMap<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap = new HashMap<Long, DiskOffering>();
    for (Object objDataDiskTemplates : dataDiskTemplateToDiskOfferingList.values()) {
        HashMap<String, String> dataDiskTemplates = (HashMap<String, String>) objDataDiskTemplates;
        Long dataDiskTemplateId;
        DiskOffering dataDiskOffering = null;
        VirtualMachineTemplate dataDiskTemplate = _entityMgr.findByUuid(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid"));
        if (dataDiskTemplate == null) {
            dataDiskTemplate = _entityMgr.findById(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid"));
            if (dataDiskTemplate == null)
                throw new InvalidParameterValueException("Unable to translate and find entity with datadisktemplateid " + dataDiskTemplates.get("datadisktemplateid"));
        }
        dataDiskTemplateId = dataDiskTemplate.getId();
        dataDiskOffering = _entityMgr.findByUuid(DiskOffering.class, dataDiskTemplates.get("diskofferingid"));
        if (dataDiskOffering == null) {
            dataDiskOffering = _entityMgr.findById(DiskOffering.class, dataDiskTemplates.get("diskofferingid"));
            if (dataDiskOffering == null)
                throw new InvalidParameterValueException("Unable to translate and find entity with diskofferingId " + dataDiskTemplates.get("diskofferingid"));
        }
        dataDiskTemplateToDiskOfferingMap.put(dataDiskTemplateId, dataDiskOffering);
    }
    return dataDiskTemplateToDiskOfferingMap;
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)65 ServerApiException (com.cloud.api.ServerApiException)22 TemplateResponse (com.cloud.api.response.TemplateResponse)20 Account (com.cloud.user.Account)16 ServerApiException (org.apache.cloudstack.api.ServerApiException)15 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 ArrayList (java.util.ArrayList)9 ListResponse (com.cloud.api.response.ListResponse)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)8 DiskOffering (com.cloud.offering.DiskOffering)8 DataCenter (com.cloud.dc.DataCenter)7 Network (com.cloud.network.Network)7 VolumeVO (com.cloud.storage.VolumeVO)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7