@Test public void testRetryCount() throws Throwable { System.setProperty(ImageEnumerationTaskService.IMAGE_ENUMERATION_RETRY_INTERVAL_SECONDS, "1"); int tasksCountBeforeRun = countImageEnumerationTaskDocuments(getHost()); ImageEnumerationTaskState adapterReq = new ImageEnumerationTaskState(); adapterReq.retryCount = 2; adapterReq.regionId = this.endpointType.name(); adapterReq.endpointType = this.endpointType.name(); adapterReq.customProperties = new HashMap<>(); adapterReq.customProperties.put("retryTest", "retryTest"); postServiceSynchronously( ImageEnumerationTaskService.FACTORY_LINK, adapterReq, ImageEnumerationTaskState.class); getHost().waitFor("Timeout waiting for retries", () -> tasksCountBeforeRun + 1 + adapterReq.retryCount == countImageEnumerationTaskDocuments(getHost())); System.clearProperty(ImageEnumerationTaskService.IMAGE_ENUMERATION_RETRY_INTERVAL_SECONDS); } }
if (!taskState.enumeratePrivateImages() && !taskState.enumeratePublicImages()) { throw new IllegalArgumentException( "Either " + ImageEnumerationTaskState.class.getSimpleName() " must be set."); if (taskState.enumeratePrivateImages() && taskState.enumeratePublicImages()) { throw new IllegalArgumentException( "Both " + ImageEnumerationTaskState.class.getSimpleName() taskState.enumeratePublicImages(), ImageEnumerationTaskState.class.getSimpleName() + "." + ImageEnumerationTaskState.FIELD_NAME_REGION_ID +
if (ctx.taskState.enumeratePrivateImages()) { adapterReq.requestType = ImageEnumerateRequestType.PRIVATE; } else if (ctx.taskState.enumeratePublicImages()) { adapterReq.requestType = ImageEnumerateRequestType.PUBLIC;
if (!taskState.enumeratePrivateImages() && !taskState.enumeratePublicImages()) { throw new IllegalArgumentException(String.format( "Either %s or %s must be set.", fieldLogger.apply(ImageEnumerationTaskState.FIELD_NAME_ENDPOINT_LINK))); if (taskState.enumeratePrivateImages() && taskState.enumeratePublicImages()) { throw new IllegalArgumentException(String.format( "Both %s and %s cannot be set.",
if (ctx.taskState.enumeratePrivateImages()) { adapterReq.requestType = ImageEnumerateRequestType.PRIVATE; } else if (ctx.taskState.enumeratePublicImages()) { adapterReq.requestType = ImageEnumerateRequestType.PUBLIC;
ImageEnumerationTaskState retryRequest = new ImageEnumerationTaskState(); retryRequest.retryCount = taskState.retryCount - 1; retryRequest.options = taskState.options;
/** * @see ImageEnumerationTaskService#validateStartPost(com.vmware.xenon.common.Operation) */ @Test public void testValidation() throws Throwable { // Either should be set { ImageEnumerationTaskState invalidState = new ImageEnumerationTaskState(); invalidState.endpointLink = null; invalidState.endpointType = null; postServiceSynchronously( ImageEnumerationTaskService.FACTORY_LINK, invalidState, ImageEnumerationTaskState.class, IllegalArgumentException.class); } // Both cannot be set { ImageEnumerationTaskState invalidState = new ImageEnumerationTaskState(); invalidState.endpointLink = "someEndpointLink"; invalidState.endpointType = "someEndpointType"; postServiceSynchronously( ImageEnumerationTaskService.FACTORY_LINK, invalidState, ImageEnumerationTaskState.class, IllegalArgumentException.class); } }
@Override public void handlePatch(Operation patchOp) { if (!patchOp.hasBody()) { patchOp.fail(new IllegalArgumentException("body is required")); return; } // Complete the operation. patchOp.complete(); ImageEnumerateRequest adapterRequest = patchOp.getBody(ImageEnumerateRequest.class); // PATCH the task with 'completed' TaskState ImageEnumerationTaskState taskResponse = new ImageEnumerationTaskState(); taskResponse.taskInfo = this.completedTaskState; if (taskResponse.taskInfo.failure != null) { taskResponse.failureMessage = taskResponse.taskInfo.failure.message; } sendRequest(Operation.createPatch(adapterRequest.taskReference).setBody(taskResponse)); } }
protected ImageEnumerationTaskState newImageEnumerationRequest() { final ImageEnumerationTaskState taskState = new ImageEnumerationTaskState(); if (isPublicImageEnumeration(this.endpointType)) { taskState.endpointType = this.endpointType; } else if (this.endpointState != null) { // Private image-enum taskState.endpointLink = this.endpointState.documentSelfLink; taskState.tenantLinks = this.endpointState.tenantLinks; } else if (this.endpointType == EP_NONE) { // No EP created at all; Request/Refer non-existing EP. taskState.endpointLink = buildUriPath(EndpointService.FACTORY_LINK, EP_NONE); } taskState.regionId = this.endpointType; return taskState; }
/** * Get the {@link EndpointState} either by type or by link. */ private DeferredResult<SendImageEnumerationAdapterContext> getEndpointState( SendImageEnumerationAdapterContext ctx) { if (ctx.taskState.enumeratePrivateImages()) { return getEndpointStateByLink(ctx); } if (ctx.taskState.enumeratePublicImages()) { return getEndpointStateByType(ctx); } // This MUST not happen due to task-state validation. return DeferredResult.completed(ctx); }
/** * Get the {@link EndpointState} either by type or by link. */ private DeferredResult<SendImageEnumerationAdapterContext> getEndpointState( SendImageEnumerationAdapterContext ctx) { if (ctx.taskState.enumeratePrivateImages()) { return getEndpointStateByLink(ctx); } if (ctx.taskState.enumeratePublicImages()) { return getEndpointStateByType(ctx); } // This MUST not happen due to task-state validation. return null; }