Search in sources :

Example 66 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class EndpointAllocationTaskServiceTest method createEndpointState.

private static EndpointState createEndpointState() {
    EndpointState endpoint = new EndpointState();
    endpoint.endpointType = EndpointType.aws.name();
    endpoint.name = "aws_endpoint";
    endpoint.endpointProperties = new HashMap<>();
    endpoint.endpointProperties.put(REGION_KEY, "test-regionId");
    endpoint.endpointProperties.put(PRIVATE_KEY_KEY, TEST_SECRETE_KEY);
    endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, TEST_ACCESS_KEY);
    endpoint.tenantLinks = Collections.singletonList("tenant-1");
    return endpoint;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 67 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class EndpointServiceTests method testCreateEndpoint.

public void testCreateEndpoint(EndpointService.EndpointState ep) throws Throwable {
    EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
    validateEndpoint.endpointState = ep;
    validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
    EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    // check endpoint document was created
    EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
    assertNotNull(endpoint);
    assertNotNull(endpoint.authCredentialsLink);
    assertNotNull(endpoint.computeLink);
    assertNotNull(endpoint.computeDescriptionLink);
    AuthCredentialsService.AuthCredentialsServiceState credentials = getServiceSynchronously(endpoint.authCredentialsLink, AuthCredentialsService.AuthCredentialsServiceState.class);
    assertNotNull(credentials);
    assertEquals(ep.endpointProperties.get(PRIVATE_KEYID_KEY), credentials.privateKeyId);
    assertEquals(ep.endpointProperties.get(PRIVATE_KEY_KEY), credentials.privateKey);
    ComputeDescriptionService.ComputeDescription cd = getServiceSynchronously(endpoint.computeDescriptionLink, ComputeDescriptionService.ComputeDescription.class);
    assertNotNull(cd);
    assertEquals(credentials.documentSelfLink, cd.authCredentialsLink);
    assertEquals(this.regionId, cd.regionId);
    assertEquals(this.environmentName, cd.environmentName);
    ComputeService.ComputeState cs = getServiceSynchronously(endpoint.computeLink, ComputeService.ComputeState.class);
    assertNotNull(cs);
    assertNotNull(cs.adapterManagementReference);
    assertEquals(ComputeDescriptionService.ComputeDescription.ComputeType.ENDPOINT_HOST, cs.type);
    assertEquals(this.environmentName, cs.environmentName);
    assertEquals(ComputeService.PowerState.ON, cs.powerState);
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService)

Example 68 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class ResourceGroomerTaskService method collectDeletedEndpoints.

/**
 * Get endpointLinks for all documents and collect deleted endpointLinks by querying for all links
 * with INCLUDE_DELETED.
 */
private void collectDeletedEndpoints(EndpointResourceDeletionRequest task, SubStage next) {
    QueryTask queryTask;
    // from all documents and query for those.
    if (isEndpointSpecified(task)) {
        queryTask = buildQueryTask(task, true, Collections.singleton(task.endpointLink));
    } else {
        Set<String> currentEndpointLinks = new HashSet<>();
        task.endpointLinksByDocumentLinks.values().stream().forEach(links -> {
            currentEndpointLinks.addAll(links);
        });
        currentEndpointLinks.addAll(task.endpointLinkByDocumentLinks.values());
        if (currentEndpointLinks.isEmpty()) {
            task.subStage = next;
            sendSelfPatch(task);
            return;
        }
        queryTask = buildQueryTask(task, true, currentEndpointLinks);
    }
    QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((response, e) -> {
        if (e != null) {
            task.failureMessage = e.getMessage();
            task.subStage = SubStage.FAILED;
            sendSelfPatch(task);
            return;
        }
        if (response.results != null && response.results.documents != null) {
            response.results.documents.values().stream().forEach(obj -> {
                EndpointState state = Utils.fromJson(obj, EndpointState.class);
                if (state.documentUpdateAction.equals(Action.DELETE.name())) {
                    task.deletedEndpointLinks.add(state.documentSelfLink);
                }
            });
        }
        if (response.results != null && response.results.nextPageLink != null) {
            processDeletedEndpointLinksQueryPage(task, response.results.nextPageLink, next);
            return;
        }
        task.subStage = next;
        sendSelfPatch(task);
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryTask(com.vmware.xenon.services.common.QueryTask) HashSet(java.util.HashSet)

Example 69 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class EndpointAllocationTaskService method updateOrCreateEndpoint.

private void updateOrCreateEndpoint(EndpointAllocationTaskState currentState) {
    EndpointState es = currentState.endpointState;
    Map<String, String> endpointProperties = currentState.endpointState.endpointProperties;
    es.endpointProperties = null;
    Operation.createPatch(this, es.documentSelfLink).setBody(es).setCompletion((o, e) -> {
        if (e != null) {
            if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) {
                logInfo(() -> String.format("Endpoint %s not found, creating new.", es.documentSelfLink));
                currentState.endpointState.endpointProperties = endpointProperties;
                createEndpoint(currentState);
            } else {
                logSevere(() -> String.format("Failed to update endpoint %s : %s", es.documentSelfLink, e.getMessage()));
                sendFailurePatch(this, currentState, e);
            }
            return;
        }
        EndpointState loadedState = o.getBody(EndpointState.class);
        loadedState.endpointProperties = endpointProperties;
        EndpointAllocationTaskState state = createUpdateSubStageTask(SubStage.INVOKE_ADAPTER);
        state.endpointState = loadedState;
        List<Operation> patchOperations = new ArrayList<>();
        if (es.computeDescriptionLink != null) {
            Operation compDescOp = Operation.createPatch(this, es.computeDescriptionLink).setBody(configureDescriptionPatch(es));
            patchOperations.add(compDescOp);
        }
        if (es.computeLink != null) {
            Operation computeOp = Operation.createPatch(this, es.computeLink).setBody(configureComputePatch(es, es.endpointProperties));
            patchOperations.add(computeOp);
        }
        if (patchOperations.size() == 0) {
            sendSelfPatch(state);
            return;
        }
        OperationJoin.create(patchOperations).setCompletion((ops, failures) -> {
            if (failures != null) {
                long firstKey = failures.keySet().iterator().next();
                failures.values().forEach(ex -> logWarning(() -> String.format("Error executing patch " + "operations while creating/updating " + "endpoint: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, failures.get(firstKey));
                return;
            }
            sendSelfPatch(state);
        }).sendWith(this);
    }).sendWith(this);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) List(java.util.List) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9