@Mapping(from = List.class, to = Action.class) public static Action map(List<AsyncTaskStatus> entity, Action template) { Action model = template != null ? template : new Action(); CreationStatus asyncStatus = null; for (AsyncTaskStatus task : entity) { asyncStatus = AsyncTaskMapper.map(task, asyncStatus); } model.setStatus(asyncStatus.value()); if (asyncStatus == CreationStatus.FAILED) { model.setFault(new Fault()); for (AsyncTaskStatus task : entity) { if (task.getException() != null) { model.getFault().setDetail(task.getException().toString()); break; } } } return model; } }
@Override public V3Action adapt(Action from) { V3Action to = new V3Action(); if (from.isSetId()) { to.setId(from.getId()); if (from.isSetHref()) { to.setHref(from.getHref()); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetAsync()) { to.setAsync(from.isAsync()); if (from.isSetBricks()) { to.setBricks(adaptOut(from.getBricks())); if (from.isSetCertificates()) { to.setCertificates(adaptOut(from.getCertificates())); if (from.isSetCheckConnectivity()) { to.setCheckConnectivity(from.isCheckConnectivity()); if (from.isSetClone()) { to.setClone(from.isClone()); if (from.isSetCluster()) { to.setCluster(adaptOut(from.getCluster()));
public static Method getExportSignature(Action action) throws NoSuchMethodException, SecurityException { if (action == null) { throw new ValidationException("Action is mandatory but was not provided."); } /** * to_path_on_host */ if (action!=null && (action.getHost()!=null && action.getHost().getId()!=null || action.getHost()!=null && action.getHost().getName()!=null) && action.getDirectory()!=null ) { return TemplateResource.class.getMethod("exportToPathOnHost", Action.class); } /** * to_export_domain */ if (action!=null && (action.getStorageDomain()!=null && action.getStorageDomain().getId()!=null || action.getStorageDomain()!=null && action.getStorageDomain().getName()!=null) ) { return TemplateResource.class.getMethod("exportToExportDomain", Action.class); } throw new ValidationException("No matching signature found, make sure that mandatory attributes are provided."); }
@Override protected Action deprecatedPopulate(Action model, List entity) { model.setId(asString(ids)); if (model.isSetFault()) { setReason(model.getFault()); } return model; }
private Guid getTargetClusterId(Action action) { if (action.isSetCluster() && action.getCluster().isSetId()) { return asGuid(action.getCluster().getId()); } // means use the cluster of the provided host return null; }
@Test public void testStartWithVm() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[]{"VmId"}, new Object[]{GUIDS[0]})); Action action = new Action(); action.setVm(new Vm()); Response response = resource.start(action); verifyActionResponse(response); verifyActionModel(((Action) response.getEntity()).getVm(), 0); }
@Test public void testExport() { setUriInfo(setUpActionExpectations(ActionType.ExportRepoImage, ExportRepoImageParameters.class, new String[]{"ImageGroupID", "DestinationDomainId"}, new Object[]{DISK_ID, GUIDS[3]}, true, true, null, null, true)); Action action = new Action(); action.setStorageDomain(new StorageDomain()); action.getStorageDomain().setId(GUIDS[3].toString()); verifyActionResponse(resource.export(action)); }
@Test public void testImportNotFound() { Action action = new Action(); action.setStorageDomain(new StorageDomain()); action.getStorageDomain().setId(GUIDS[2].toString()); action.setCluster(new org.ovirt.engine.api.model.Cluster()); action.getCluster().setId(GUIDS[1].toString()); setUpGetEntityExpectations(StorageDomainType.ImportExport, STORAGE_DOMAIN_ID, true); verifyNotFoundException(assertThrows(WebApplicationException.class, () -> resource.doImport(action))); }
@Test public void testUndelete() { setUriInfo(setUpActionExpectations(ActionType.DisplayAllAuditLogAlerts, ActionParametersBase.class, new String[] {}, new Object[] {}, true, true)); collection.undelete(new Action()); }
RunVmParams params; ActionType actionType; if (action.isSetVm()) { Vm vm = action.getVm(); actionType = ActionType.RunVmOnce; params = createRunVmOnceParams(vm, action.isSetVolatile() && action.isVolatile()); } else { actionType = ActionType.RunVm; params = new RunVmParams(guid); if (action.isSetPause() && action.isPause()) { params.setRunAndPause(true); boolean sysPrepSet = action.isSetUseSysprep(); boolean useSysPrep = sysPrepSet && action.isUseSysprep(); boolean cloudInitSet = action.isSetUseCloudInit(); boolean useCloudInit = cloudInitSet && action.isUseCloudInit(); if (useSysPrep && useCloudInit) { Fault fault = new Fault();
@Test public void testMigrateWithHostName() { setUpGetHostByNameExpectations(1); setUriInfo(setUpActionExpectations(ActionType.MigrateVmToServer, MigrateVmToServerParameters.class, new String[] { "VmId", "VdsId", "ForceMigrationForNonMigratableVm" }, new Object[] { GUIDS[0], GUIDS[1], Boolean.FALSE })); Action action = new Action(); action.setHost(new Host()); action.getHost().setName(NAMES[1]); verifyActionResponse(resource.migrate(action)); }
@Mapping(from = Action.class, to = VdsOperationActionParameters.class) public static VdsOperationActionParameters map(Action action, VdsOperationActionParameters params) { params.setPassword(action.getRootPassword()); if (action.isSetSsh()) { if (action.getSsh().isSetUser()) { if (action.getSsh().getUser().isSetPassword()) { params.setPassword(action.getSsh().getUser().getPassword()); if (action.getSsh().getUser().isSetUserName()) { params.getvds().setSshUsername(action.getSsh().getUser().getUserName()); if (action.getSsh().isSetPort()) { params.getvds().setSshPort(action.getSsh().getPort()); if (action.getSsh().isSetFingerprint()) { params.getvds().setSshKeyFingerprint(action.getSsh().getFingerprint()); if (action.getSsh().isSetAuthenticationMethod()) { params.setAuthMethod(mapSshAuthenticationMethod(action.getSsh().getAuthenticationMethod())); if (action.isSetHost()) { if (action.getHost().isSetOverrideIptables()) { params.setOverrideFirewall(action.getHost().isOverrideIptables());
@Override public Response register(Action action) { ImportVmFromConfParameters params = new ImportVmFromConfParameters(); if (action.isSetRegistrationConfiguration()) { validateClusterMappings(action); validateRoleMappings(action); action.getVnicProfileMappings()); params.setExternalVnicProfileMappings(vnicProfileMappings); ExternalRegistrationConfigurationMapper.mapFromModel(action.getRegistrationConfiguration(), params); params.setReassignBadMacs(getReassignBadMacs(action)); params.setContainerId(guid); params.setStorageDomainId(parent.getStorageDomainId()); if (action.isSetCluster()) { params.setClusterId(getClusterId(action)); if (action.isSetClone()) { params.setImportAsNewEntity(action.isClone()); if (action.isSetVm() && action.getVm().isSetName()) { params.getVm().setName(action.getVm().getName()); if (action.isSetAllowPartialImport()) { params.setAllowPartialImport(action.isAllowPartialImport());
@Test public void testSetOption() { setupParentExpectations(); resource.setParent(volumesResourceMock); setUriInfo(setUpActionExpectations(ActionType.SetGlusterVolumeOption, GlusterVolumeOptionParameters.class, new String[] { "VolumeId" }, new Object[] { GUIDS[0] })); Action action = new Action(); action.setOption(new Option()); action.getOption().setName("auth.allow"); action.getOption().setValue("*"); verifyActionResponse(resource.setOption(action)); }
@Test public void testStartWithPauseAndStateless() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "RunAndPause", "RunAsStateless" }, new Object[] { GUIDS[0], true, Boolean.TRUE })); Action action = new Action(); action.setPause(true); action.setVm(new Vm()); action.getVm().setStateless(true); verifyActionResponse(resource.start(action)); }
@Test public void testFenceStatusFailure() { FenceOperationResult retVal = new FenceOperationResult(FenceOperationResult.Status.ERROR, PowerStatus.UNKNOWN, "some_error"); setUpEntityQueryExpectations(QueryType.GetVdsFenceStatus, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, retVal); Action action = new Action(); action.setFenceType(FenceType.STATUS.value()); Response response = resource.fence(action); Action actionReturned = (Action)response.getEntity(); assertEquals(actionReturned.getStatus(), CreationStatus.FAILED.value()); assertNotNull(actionReturned.getFault()); assertEquals("some_error", actionReturned.getFault().getReason()); }
@Override public Response approve(Action action) { if (action.isSetCluster() && (action.getCluster().isSetId() || action.getCluster().isSetName())) { update(setCluster(get(), action.getCluster())); } ApproveVdsParameters params = new ApproveVdsParameters(guid); params = (ApproveVdsParameters) getMapper (Action.class, VdsOperationActionParameters.class).map(action, params); // Set pk authentication as default params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.PublicKey); if (action.isSetRootPassword()) { params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.Password); params.setRootPassword(action.getRootPassword()); } else if (action.isSetSsh() && action.getSsh().isSetAuthenticationMethod()) { if (action.getSsh().getAuthenticationMethod() == SshAuthenticationMethod.PASSWORD) { params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.Password); if (action.getSsh().isSetUser() && action.getSsh().getUser().isSetPassword()) { params.setPassword(action.getSsh().getUser().getPassword()); } } } // by default activate the host after approval boolean activate = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, BackendHostsResource.ACTIVATE, true, true); params.setActivateHost(activate); return doAction(ActionType.ApproveVds, params, action); }
public void doTestImport(StorageDomain storageDomain, org.ovirt.engine.api.model.Cluster cluster, boolean importAsNewEntity) { setUpGetEntityExpectations(1, StorageDomainType.ImportExport, GUIDS[2]); setUriInfo(setUpActionExpectations(ActionType.ImportVmTemplate, ImportVmTemplateParameters.class, new String[] { "ContainerId", "StorageDomainId", "SourceDomainId", "DestDomainId", "StoragePoolId", "ClusterId", "ImportAsNewEntity" }, new Object[] { TEMPLATE_ID, GUIDS[2], STORAGE_DOMAIN_ID, GUIDS[2], DATA_CENTER_ID, GUIDS[1], importAsNewEntity })); Action action = new Action(); action.setStorageDomain(storageDomain); action.setCluster(cluster); action.setClone(importAsNewEntity); verifyActionResponse(resource.doImport(action)); }
@Test public void testUndoSnapshot() { setUriInfo(setUpActionExpectations(ActionType.RestoreAllSnapshots, RestoreAllSnapshotsParameters.class, new String[] { "VmId", "SnapshotAction" }, new Object[] { GUIDS[0], SnapshotActionEnum.UNDO })); Response response = resource.undoSnapshot(new Action()); verifyActionResponse(response); Action action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(CreationStatus.COMPLETE.value(), action.getStatus()); }