@Override public String getEventDescription() { StringBuilder descBuilder = new StringBuilder(); if (getDestinationZoneIds() != null) { for (Long destId : getDestinationZoneIds()) { descBuilder.append(", "); descBuilder.append(this._uuidMgr.getUuid(DataCenter.class, destId)); } if (descBuilder.length() > 0) { descBuilder.deleteCharAt(0); } } return "copying template: " + this._uuidMgr.getUuid(VirtualMachineTemplate.class, getId()) +((getSourceZoneId() != null) ? " from zone: " + this._uuidMgr.getUuid(DataCenter.class, getSourceZoneId()) : "") + ((descBuilder.length() > 0) ? " to zones: " + descBuilder.toString() : ""); }
"Both destzoneid and destzoneids cannot be specified at the same time."); CallContext.current().setEventDetails(getEventDescription()); VirtualMachineTemplate template = _templateService.copyTemplate(this); template, getDestinationZoneIds(), false); TemplateResponse response = new TemplateResponse(); if (listResponse != null && !listResponse.isEmpty()) { response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
@Test public void testDestZoneidAndDestZoneIdListBothPresent() throws ResourceAllocationException { try { copyTemplateCmd = new CopyTemplateCmd(); copyTemplateCmd.destZoneId = -1L; copyTemplateCmd.destZoneIds = new ArrayList<>(); copyTemplateCmd.destZoneIds.add(-1L); copyTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both destzoneid and destzoneids are passed"); } } }
@Override public Long getInstanceId() { return getId(); }
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { copyTemplateCmd = new CopyTemplateCmd(); copyTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("API should fail when no parameters are passed."); } } }
@Override public long getEntityOwnerId() { VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); if (template != null) { return template.getAccountId(); } // bad id given, parent this command to SYSTEM so ERROR events are tracked return Account.ACCOUNT_ID_SYSTEM; }
@Override @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true) public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException { Long templateId = cmd.getId(); Long userId = CallContext.current().getCallingUserId(); Long sourceZoneId = cmd.getSourceZoneId(); List<Long> destZoneIds = cmd.getDestinationZoneIds(); Account caller = CallContext.current().getCallingAccount();