private void checkJob(AsyncJob<?> query) { assert query.getStatus().code() >= 0 : query; assert query.getResultCode().code() >= 0 : query; assert query.getProgress() >= 0 : query; if (query.getResultCode() == ResultCode.SUCCESS) { if (query.getResult() != null) { assertEquals(query.getResult().getClass().getPackage(), AsyncJob.class.getPackage()); } } else if (query.getResultCode() == ResultCode.FAIL) { assert query.getResult() == null : query; assert query.getError() != null : query; } else { assert query.getResult() == null : query; } }
public void testOverloadedKeyName() { InputStream is = getClass().getResourceAsStream("/queryasyncjobresultresponse-createtemplate.json"); ParseAsyncJobFromHttpResponse parser = i.getInstance(ParseAsyncJobFromHttpResponse.class); AsyncJob<?> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertTrue(response.getResult() instanceof Template, "response expected to be Template, actually is " + response.getResult().getClass()); is = getClass().getResourceAsStream("/queryasyncjobresultresponse-extracttemplate.json"); response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertTrue(response.getResult() instanceof TemplateExtraction, "response expected to be TemplateExtraction, actually is " + response.getResult().getClass()); } }
public T fromAsyncJob(AsyncJob<S> in) { return this .accountId(in.getAccountId()) .cmd(in.getCmd()) .created(in.getCreated()) .id(in.getId()) .instanceId(in.getInstanceId()) .instanceType(in.getInstanceType()) .progress(in.getProgress()) .result(in.getResult()) .resultCode(in.getResultCode()) .resultType(in.getResultType()) .status(in.getStatus()) .userId(in.getUserId()) .error(in.getError()); }
public T fromAsyncJob(AsyncJob<S> in) { return this .accountId(in.getAccountId()) .cmd(in.getCmd()) .created(in.getCreated()) .id(in.getId()) .instanceId(in.getInstanceId()) .instanceType(in.getInstanceType()) .progress(in.getProgress()) .result(in.getResult()) .resultCode(in.getResultCode()) .resultType(in.getResultType()) .status(in.getStatus()) .userId(in.getUserId()) .error(in.getError()); }
public void testOverloadedKeyName() { InputStream is = getClass().getResourceAsStream("/queryasyncjobresultresponse-createtemplate.json"); ParseAsyncJobFromHttpResponse parser = i.getInstance(ParseAsyncJobFromHttpResponse.class); AsyncJob<?> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertTrue(response.getResult() instanceof Template, "response expected to be Template, actually is " + response.getResult().getClass()); is = getClass().getResourceAsStream("/queryasyncjobresultresponse-extracttemplate.json"); response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); assertTrue(response.getResult() instanceof TemplateExtraction, "response expected to be TemplateExtraction, actually is " + response.getResult().getClass()); } }
private void checkJob(AsyncJob<?> query) { assert query.getStatus().code() >= 0 : query; assert query.getResultCode().code() >= 0 : query; assert query.getProgress() >= 0 : query; if (query.getResultCode() == ResultCode.SUCCESS) { if (query.getResult() != null) { assertEquals(query.getResult().getClass().getPackage(), AsyncJob.class.getPackage()); } } else if (query.getResultCode() == ResultCode.FAIL) { assert query.getResult() == null : query; assert query.getError() != null : query; } else { assert query.getResult() == null : query; } }
public T fromAsyncJob(AsyncJob<S> in) { return this .accountId(in.getAccountId()) .cmd(in.getCmd()) .created(in.getCreated()) .id(in.getId()) .instanceId(in.getInstanceId()) .instanceType(in.getInstanceType()) .progress(in.getProgress()) .result(in.getResult()) .resultCode(in.getResultCode()) .resultType(in.getResultType()) .status(in.getStatus()) .userId(in.getUserId()) .error(in.getError()); }
/** * * @param job * @return result of the job's execution * @throws ExecutionException * if the job contained an error */ public <T> T apply(AsyncCreateResponse job) { boolean completed = jobComplete.apply(job.getJobId()); logger.trace("<< job(%s) complete(%s)", job, completed); AsyncJob<T> jobWithResult = client.getAsyncJobClient().<T> getAsyncJob(job.getJobId()); checkState(completed, "job %s failed to complete in time %s", job.getJobId(), jobWithResult); if (jobWithResult.getError() != null) throw new UncheckedExecutionException(String.format("job %s failed with exception %s", job.getJobId(), jobWithResult.getError().toString())) { }; return jobWithResult.getResult(); } }
/** * * @param job * @return result of the job's execution * @throws ExecutionException * if the job contained an error */ public <T> T apply(AsyncCreateResponse job) { boolean completed = jobComplete.apply(job.getJobId()); logger.trace("<< job(%s) complete(%s)", job, completed); AsyncJob<T> jobWithResult = client.getAsyncJobClient().<T> getAsyncJob(job.getJobId()); checkState(completed, "job %s failed to complete in time %s", job.getJobId(), jobWithResult); if (jobWithResult.getError() != null) throw new UncheckedExecutionException(String.format("job %s failed with exception %s", job.getJobId(), jobWithResult.getError().toString())) { }; return jobWithResult.getResult(); } }
/** * * @param job * @return result of the job's execution * @throws ExecutionException * if the job contained an error */ public <T> T apply(AsyncCreateResponse job) { boolean completed = jobComplete.apply(job.getJobId()); logger.trace("<< job(%s) complete(%s)", job, completed); AsyncJob<T> jobWithResult = client.getAsyncJobApi().<T> getAsyncJob(job.getJobId()); checkState(completed, "job %s failed to complete in time %s", job.getJobId(), jobWithResult); if (jobWithResult.getError() != null) throw new UncheckedExecutionException(String.format("job %s failed with exception %s", job.getJobId(), jobWithResult.getError().toString())) { }; return jobWithResult.getResult(); } }
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate") public void testExtractTemplate() throws Exception { // Initiate the extraction and wait for it to complete AsyncCreateResponse response = client.getTemplateClient().extractTemplate(registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId()); assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString()); // Get the result AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobClient().getAsyncJob(response.getJobId()); TemplateExtraction extract = asyncJob.getResult(); assertNotNull(extract); // Check that the URL can be retrieved String extractUrl = extract.getUrl(); assertNotNull(extractUrl); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri); }
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate") public void testExtractTemplate() throws Exception { // Initiate the extraction and wait for it to complete AsyncCreateResponse response = client.getTemplateApi().extractTemplate(registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId()); assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString()); // Get the result AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobApi().getAsyncJob(response.getJobId()); TemplateExtraction extract = asyncJob.getResult(); assertNotNull(extract); // Check that the URL can be retrieved String extractUrl = extract.getUrl(); assertNotNull(extractUrl); URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8")); assertTrue(cloudStackContext.utils().http().exists(uri), "does not exist: " + uri); }
public void testAssociateDisassociatePublicIPAddress() throws Exception { if (!networksEnabled) return; AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone( Iterables.get(client.getNetworkClient().listNetworks(), 0).getZoneId()); checkState(jobComplete.apply(job.getJobId()), "job %s failed to complete", job.getJobId()); ip = client.getAsyncJobClient().<PublicIPAddress> getAsyncJob(job.getJobId()).getResult(); checkIP(ip); }
public void testAssociateDisassociatePublicIPAddress() throws Exception { if (!networksEnabled) return; AsyncCreateResponse job = client.getAddressApi().associateIPAddressInZone( Iterables.get(client.getNetworkApi().listNetworks(), 0).getZoneId()); checkState(jobComplete.apply(job.getJobId()), "job %s failed to complete", job.getJobId()); ip = client.getAsyncJobApi().<PublicIPAddress> getAsyncJob(job.getJobId()).getResult(); checkIP(ip); }
public static VirtualMachine createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions options, String zoneId, String templateId, CloudStackClient client, Predicate<String> jobComplete, Predicate<VirtualMachine> virtualMachineRunning) { String serviceOfferingId = DEFAULT_SIZE_ORDERING.min(client.getOfferingClient().listServiceOfferings()).getId(); System.out.printf("serviceOfferingId %s, templateId %s, zoneId %s, options %s%n", serviceOfferingId, templateId, zoneId, options); AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(zoneId, serviceOfferingId, templateId, options); assertTrue(jobComplete.apply(job.getJobId())); AsyncJob<VirtualMachine> jobWithResult = client.getAsyncJobClient().<VirtualMachine> getAsyncJob(job.getJobId()); if (jobWithResult.getError() != null) Throwables.propagate(new ExecutionException(String.format("job %s failed with exception %s", job.getId(), jobWithResult.getError().toString())) { }); VirtualMachine vm = jobWithResult.getResult(); if (vm.isPasswordEnabled()) { assert vm.getPassword() != null : vm; } assertTrue(virtualMachineRunning.apply(vm)); assertEquals(vm.getServiceOfferingId(), serviceOfferingId); assertEquals(vm.getTemplateId(), templateId); assertEquals(vm.getZoneId(), zoneId); return vm; }
@Test public void testEnableDisableAccount() { skipIfNotGlobalAdmin(); Account testAccount = null; try { testAccount = createTestAccount(globalAdminClient, prefix); AsyncCreateResponse response = domainAdminClient.getAccountClient() .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); assertNotNull(response); assertTrue(jobComplete.apply(response.getJobId())); AsyncJob<Account> job = domainAdminClient.getAsyncJobClient().getAsyncJob(response.getJobId()); assertEquals(job.getResult().getState(), Account.State.DISABLED); Account updated = domainAdminClient.getAccountClient() .enableAccount(testAccount.getName(), testAccount.getDomainId()); assertNotNull(updated); assertEquals(updated.getState(), Account.State.ENABLED); } finally { if (testAccount != null) { globalAdminClient.getAccountClient().deleteAccount(testAccount.getId()); } } }
@Test(dependsOnMethods = "testCreateVirtualMachine") public void testLifeCycle() throws Exception { String job = client.getVirtualMachineApi().stopVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.STOPPED); if (vm.isPasswordEnabled()) { job = client.getVirtualMachineApi().resetPasswordForVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getAsyncJobApi().<VirtualMachine> getAsyncJob(job).getResult(); if (vm.getPassword() != null) { conditionallyCheckSSH(); } } job = client.getVirtualMachineApi().startVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.RUNNING); job = client.getVirtualMachineApi().rebootVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.RUNNING); }
@Test(dependsOnMethods = "testCreateVirtualMachine") public void testLifeCycle() throws Exception { String job = client.getVirtualMachineClient().stopVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.STOPPED); if (vm.isPasswordEnabled()) { job = client.getVirtualMachineClient().resetPasswordForVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getAsyncJobClient().<VirtualMachine> getAsyncJob(job).getResult(); if (vm.getPassword() != null) { conditionallyCheckSSH(); } } job = client.getVirtualMachineClient().startVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.RUNNING); job = client.getVirtualMachineClient().rebootVirtualMachine(vm.getId()); assertTrue(jobComplete.apply(job)); vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId()); assertEquals(vm.getState(), VirtualMachine.State.RUNNING); }
@Test public void testEnableDisableAccount() { skipIfNotGlobalAdmin(); Account testAccount = null; try { testAccount = createTestAccount(globalAdminClient, prefix); AsyncCreateResponse response = domainAdminClient.getAccountApi() .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); assertNotNull(response); assertTrue(adminJobComplete.apply(response.getJobId())); AsyncJob<Account> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId()); assertEquals(job.getResult().getState(), Account.State.DISABLED); Account updated = domainAdminClient.getAccountApi() .enableAccount(testAccount.getName(), testAccount.getDomainId()); assertNotNull(updated); assertEquals(updated.getState(), Account.State.ENABLED); } finally { if (testAccount != null) { globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } } }
assertEquals(job.getResult().getState(), User.State.DISABLED);