Search in sources :

Example 6 with EndpointConfigRequest

use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.

the class VSphereEndpointAdapterService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
    if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
        checkIfAccountExistsAndGetExistingDocuments(body, op);
        return;
    }
    EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate(body));
}
Also used : EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 7 with EndpointConfigRequest

use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.

the class AWSEndpointAdapterService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
    if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
        checkIfAccountExistsAndGetExistingDocuments(body, op);
        return;
    }
    EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate(body));
}
Also used : EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 8 with EndpointConfigRequest

use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.

the class AzureEndpointAdapterService method validate.

private BiConsumer<AuthCredentialsServiceState, BiConsumer<ServiceErrorResponse, Throwable>> validate(EndpointConfigRequest body) {
    return (credentials, callback) -> {
        try {
            Boolean shouldProvision = Boolean.parseBoolean(body.endpointProperties.get(AZURE_PROVISIONING_PERMISSION));
            validateEndpointUniqueness(credentials, body.checkForEndpointUniqueness, body.tenantLinks).thenCompose(aVoid -> validateCredentials(credentials)).thenCompose(subscription -> getPermissions(credentials)).thenCompose(permList -> verifyPermissions(permList, shouldProvision)).whenComplete((aVoid, e) -> {
                if (e == null) {
                    callback.accept(null, null);
                    return;
                }
                if (e instanceof CompletionException) {
                    e = e.getCause();
                }
                final LocalizableValidationException localizableExc;
                if (e instanceof LocalizableValidationException) {
                    localizableExc = (LocalizableValidationException) e;
                } else {
                    // Azure doesn't send us any meaningful status code to work with
                    localizableExc = new LocalizableValidationException(e, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE);
                }
                ServiceErrorResponse rsp = Utils.toServiceErrorResponse(localizableExc);
                rsp.statusCode = STATUS_CODE_UNAUTHORIZED;
                callback.accept(rsp, localizableExc);
            });
        } catch (Throwable e) {
            logSevere(e);
            ServiceErrorResponse rsp = new ServiceErrorResponse();
            rsp.message = "Invalid Azure credentials";
            rsp.statusCode = STATUS_CODE_UNAUTHORIZED;
            callback.accept(rsp, e);
        }
    };
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QUERY_PARAM_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION) QueryTask(com.vmware.xenon.services.common.QueryTask) PROVIDER_PERMISSIONS_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVIDER_PERMISSIONS_URI) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) SubscriptionInner(com.microsoft.azure.management.resources.implementation.SubscriptionInner) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE) URI(java.net.URI) Permission(com.vmware.photon.controller.model.adapters.azure.model.permission.Permission) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) AUTHORIZATION_NAMESPACE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTHORIZATION_NAMESPACE) PROVIDER_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.PROVIDER_REST_API_VERSION) CompletionException(java.util.concurrent.CompletionException) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) Optional(java.util.Optional) AzureUtils.getAzureConfig(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getAzureConfig) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PermissionList(com.vmware.photon.controller.model.adapters.azure.model.permission.PermissionList) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) SubscriptionState(com.microsoft.azure.management.resources.SubscriptionState) USER_LINK_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.USER_LINK_KEY) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) SubscriptionClientImpl(com.microsoft.azure.management.resources.implementation.SubscriptionClientImpl) ArrayList(java.util.ArrayList) ZONE_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ZONE_KEY) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BiConsumer(java.util.function.BiConsumer) Retriever(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils.Retriever) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) EndpointAdapterUtils(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils) AZURE_TENANT_ID(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_TENANT_ID) SUPPORT_DATASTORES(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.SUPPORT_DATASTORES) AZURE_PROVISIONING_PERMISSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_PROVISIONING_PERMISSION) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) REGION_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.REGION_KEY) SUPPORT_PUBLIC_IMAGES(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.SUPPORT_PUBLIC_IMAGES) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) CompletionException(java.util.concurrent.CompletionException) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse)

Example 9 with EndpointConfigRequest

use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.

the class EndpointAllocationTaskService method validateCredentials.

private void validateCredentials(EndpointAllocationTaskState currentState, SubStage next) {
    EndpointConfigRequest req = new EndpointConfigRequest();
    req.requestType = RequestType.VALIDATE;
    req.endpointProperties = currentState.endpointState.endpointProperties;
    req.tenantLinks = currentState.tenantLinks;
    req.checkForEndpointUniqueness = currentState.checkForEndpointUniqueness;
    if (currentState.endpointState.documentSelfLink != null) {
        req.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.endpointState.documentSelfLink);
    }
    req.isMockRequest = currentState.options.contains(TaskOption.IS_MOCK);
    Operation.createPatch(currentState.adapterReference).setBody(req).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> e.getMessage());
            sendFailurePatch(this, currentState, e);
            return;
        }
        EndpointAllocationTaskState st = createUpdateSubStageTask(next);
        if (o.hasBody() && currentState.taskSubStage == SubStage.VALIDATE_CREDENTIALS) {
            CertificateInfoServiceErrorResponse errorResponse = o.getBody(CertificateInfoServiceErrorResponse.class);
            if (CertificateInfoServiceErrorResponse.KIND.equals(errorResponse.documentKind)) {
                st.taskInfo.failure = errorResponse;
                st.taskInfo.stage = TaskStage.FAILED;
                if (errorResponse.certificateInfo != null) {
                    st.certificateInfo = errorResponse.certificateInfo;
                }
            }
        }
        sendSelfPatch(st);
    }).sendWith(this);
}
Also used : 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) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse)

Aggregations

EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)9 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)5 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)5 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)5 DeferredResult (com.vmware.xenon.common.DeferredResult)5 LocalizableValidationException (com.vmware.xenon.common.LocalizableValidationException)5 Operation (com.vmware.xenon.common.Operation)5 Utils (com.vmware.xenon.common.Utils)5 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5 List (java.util.List)5 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)4 ENDPOINT_LINK_PROP_NAME (com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME)3 UriPaths (com.vmware.photon.controller.model.UriPaths)3 AdapterTypePath (com.vmware.photon.controller.model.UriPaths.AdapterTypePath)3 PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)3 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)3 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)3