org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended

Here are the examples of the java api org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

86 Examples 7

19 Source : ServiceOperationGetterTest.java
with Apache License 2.0
from cloudfoundry-incubator

clreplaced ServiceOperationGetterTest {

    private static final String SERVICE_NAME = "service";

    private static final UUID SERVICE_GUID = UUID.randomUUID();

    @Mock
    private ProcessContext context;

    @Mock
    private CloudServiceInstanceExtended service;

    @Mock
    private CloudControllerClient client;

    private ServiceOperationGetter serviceOperationGetter;

    @BeforeEach
    void setUp() throws Exception {
        MockitoAnnotations.openMocks(this).close();
        serviceOperationGetter = new ServiceOperationGetter();
    }

    static Stream<Arguments> testGetLastServiceOperation() {
        return Stream.of(// (1) Test with create succeeded operation
        Arguments.of(ServiceOperation.Type.CREATE, ServiceOperation.State.SUCCEEDED, "created", new ServiceOperation(ServiceOperation.Type.CREATE, "created", ServiceOperation.State.SUCCEEDED)), // (2) Test with delete service in progress operation
        Arguments.of(ServiceOperation.Type.DELETE, ServiceOperation.State.IN_PROGRESS, null, new ServiceOperation(ServiceOperation.Type.DELETE, null, ServiceOperation.State.IN_PROGRESS)), // (3) Test with missing service enreplacedy
        Arguments.of(null, null, null, null));
    }

    @ParameterizedTest
    @MethodSource
    void testGetLastServiceOperation(ServiceOperation.Type serviceOperationType, ServiceOperation.State serviceOperationState, String description, ServiceOperation expectedServiceOperation) {
        when(service.getName()).thenReturn(SERVICE_NAME);
        if (serviceOperationState != null && serviceOperationType != null) {
            when(service.getLastOperation()).thenReturn(new ServiceOperation(serviceOperationType, description, serviceOperationState));
        }
        when(client.getServiceInstance(SERVICE_NAME, false)).thenReturn(service);
        when(context.getControllerClient()).thenReturn(client);
        ServiceOperation serviceOperation = serviceOperationGetter.getLastServiceOperation(context.getControllerClient(), service);
        replacedertServiceOperation(expectedServiceOperation, serviceOperation);
    }

    private void replacedertServiceOperation(ServiceOperation expectedServiceOperation, ServiceOperation serviceOperation) {
        if (expectedServiceOperation != null) {
            replacedertEquals(expectedServiceOperation.getState(), serviceOperation.getState());
            replacedertEquals(expectedServiceOperation.getType(), serviceOperation.getType());
            replacedertEquals(expectedServiceOperation.getDescription(), serviceOperation.getDescription());
        } else {
            replacedertNull(serviceOperation);
        }
    }

    static Stream<Arguments> testGetLastDeleteServiceOperation() {
        return Stream.of(// (1) test with null metadata returns null service operation
        Arguments.of(true, false, null), // (2) test with delete event returns succeeded operation
        Arguments.of(false, true, new ServiceOperation(ServiceOperation.Type.DELETE, null, ServiceOperation.State.SUCCEEDED)), // (3) test with non-delete event returns in progress operation
        Arguments.of(false, false, new ServiceOperation(ServiceOperation.Type.DELETE, null, ServiceOperation.State.IN_PROGRESS)));
    }

    @ParameterizedTest
    @MethodSource
    void testGetLastDeleteServiceOperation(boolean missingServiceMetadata, boolean containsDeleteEvent, ServiceOperation expectedOperation) {
        prepareService(missingServiceMetadata);
        prepareEvents(containsDeleteEvent);
        when(context.getControllerClient()).thenReturn(client);
        ServiceOperation serviceOperation = serviceOperationGetter.getLastServiceOperation(context.getControllerClient(), service);
        replacedertEquals(expectedOperation, serviceOperation);
    }

    private void prepareService(boolean isMissingServiceMetadata) {
        if (!isMissingServiceMetadata) {
            when(service.getMetadata()).thenReturn(ImmutableCloudMetadata.of(SERVICE_GUID));
        }
    }

    private void prepareEvents(boolean containsDeleteEvent) {
        CloudEvent event;
        if (containsDeleteEvent) {
            event = ImmutableCloudEvent.builder().type("audit.service_instance.delete").build();
        } else {
            event = ImmutableCloudEvent.builder().type("audit.service_instance.create").build();
        }
        when(client.getEventsByActee(SERVICE_GUID)).thenReturn(List.of(event));
    }
}

19 Source : UpdateServiceMetadataStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private void prepareClient(CloudServiceInstanceExtended serviceToProcess) {
    when(client.getServiceInstance(SERVICE_NAME)).thenReturn(serviceToProcess);
}

19 Source : UpdateServiceMetadataStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private void prepareServiceToProcess(CloudServiceInstanceExtended serviceToProcess) {
    context.setVariable(Variables.SERVICE_TO_PROCESS, serviceToProcess);
}

19 Source : PollServiceInProgressOperationsExecutionTest.java
with Apache License 2.0
from cloudfoundry-incubator

private void prepareServiceOperationGetter(List<CloudServiceInstanceExtended> services, List<ServiceOperation.Type> servicesOperationTypes, List<ServiceOperation.State> servicesOperationStates) {
    for (int i = 0; i < services.size(); i++) {
        CloudServiceInstanceExtended service = services.get(i);
        ServiceOperation.Type serviceOperationType = servicesOperationTypes.get(i);
        ServiceOperation.State serviceOperationState = servicesOperationStates.get(i);
        if (serviceOperationType != null && serviceOperationState != null) {
            when(serviceOperationGetter.getLastServiceOperation(any(), eq(service))).thenReturn(new ServiceOperation(serviceOperationType, "", serviceOperationState));
        }
    }
}

19 Source : ServiceOperationGetter.java
with Apache License 2.0
from cloudfoundry-incubator

private ServiceOperation getLastDeleteServiceOperation(CloudControllerClient client, CloudServiceInstanceExtended service) {
    if (service.getMetadata() == null) {
        return null;
    }
    boolean isServiceDeleted = isServiceDeleted(client, service.getMetadata().getGuid());
    ServiceOperation.State operationState = isServiceDeleted ? ServiceOperation.State.SUCCEEDED : ServiceOperation.State.IN_PROGRESS;
    return new ServiceOperation(ServiceOperation.Type.DELETE, ServiceOperation.Type.DELETE.name(), operationState);
}

19 Source : ServiceOperationGetter.java
with Apache License 2.0
from cloudfoundry-incubator

public ServiceOperation getLastServiceOperation(CloudControllerClient client, CloudServiceInstanceExtended service) {
    CloudServiceInstance serviceInstance = client.getServiceInstance(service.getName(), false);
    if (serviceInstance == null) {
        return getLastDeleteServiceOperation(client, service);
    }
    return serviceInstance.getLastOperation();
}

19 Source : ServiceOperationExecutor.java
with Apache License 2.0
from cloudfoundry-incubator

public void executeServiceOperation(CloudServiceInstanceExtended service, Runnable serviceOperation, StepLogger stepLogger) {
    executeServiceOperation(service, () -> {
        serviceOperation.run();
        return null;
    }, stepLogger);
}

19 Source : ServiceOperationExecutor.java
with Apache License 2.0
from cloudfoundry-incubator

public <T> T executeServiceOperation(CloudServiceInstanceExtended service, Supplier<T> serviceOperation, StepLogger stepLogger) {
    try {
        return serviceOperation.get();
    } catch (CloudOperationException e) {
        if (!service.isOptional()) {
            if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) {
                throw new CloudServiceBrokerException(e);
            }
            throw new CloudControllerException(e);
        }
        stepLogger.warn(e, Messages.COULD_NOT_EXECUTE_OPERATION_OVER_OPTIONAL_SERVICE, service.getName());
        return null;
    }
}

19 Source : UpdateServiceMetadataStep.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected MethodExecution<String> executeOperation(ProcessContext context, CloudControllerClient client, CloudServiceInstanceExtended service) {
    getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0, service.getName(), service.getResourceName());
    UUID serviceGuid = client.getServiceInstance(service.getName()).getMetadata().getGuid();
    client.updateServiceInstanceMetadata(serviceGuid, service.getV3Metadata());
    getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0_DONE, service.getName());
    return new MethodExecution<>(null, MethodExecution.ExecutionState.EXECUTING);
}

19 Source : UpdateServiceMetadataExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
public AsyncExecutionState execute(ProcessContext context) {
    CloudServiceInstanceExtended serviceInstance = context.getVariable(Variables.SERVICE_TO_PROCESS);
    context.getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0, serviceInstance.getName());
    updateMetadata(context.getControllerClient(), serviceInstance);
    context.getStepLogger().debug(Messages.UPDATING_METADATA_OF_SERVICE_INSTANCE_0_DONE, serviceInstance.getName());
    return AsyncExecutionState.FINISHED;
}

19 Source : PollServiceOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

private ServiceOperation getLastServiceOperation(ProcessContext context, CloudServiceInstanceExtended service) {
    return serviceOperationGetter.getLastServiceOperation(context.getControllerClient(), service);
}

19 Source : PollServiceDeleteOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected void reportServiceState(ProcessContext context, CloudServiceInstanceExtended service, ServiceOperation lastServiceOperation) {
    if (lastServiceOperation.getState() == ServiceOperation.State.SUCCEEDED) {
        context.getStepLogger().debug(getSuccessMessage(service));
        return;
    }
    if (lastServiceOperation.getState() == ServiceOperation.State.FAILED) {
        throw new SLException(getFailureMessage(service, lastServiceOperation));
    }
}

19 Source : PollServiceCreateOrUpdateOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean shouldFail(CloudServiceInstanceExtended service) {
    return !service.isOptional();
}

19 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean shouldUpdatePlan(CloudServiceInstanceExtended service, CloudServiceInstance existingService) {
    return !Objects.equals(service.getPlan(), existingService.getPlan());
}

19 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private SLException getServiceRecreationNeededException(CloudServiceInstanceExtended service, CloudServiceInstance existingService) {
    return new SLException(Messages.ERROR_SERVICE_NEEDS_TO_BE_RECREATED_BUT_FLAG_NOT_SET, service.getResourceName(), buildServiceType(service), existingService.getName(), buildServiceType(existingService));
}

19 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean shouldUpdateKeys(CloudServiceInstanceExtended service, List<CloudServiceKey> serviceKeys) {
    return !(service.isUserProvided() || CollectionUtils.isEmpty(serviceKeys));
}

19 Source : CollectServicesInProgressStateStep.java
with Apache License 2.0
from cloudfoundry-incubator

protected boolean isServiceOperationInProgress(CloudServiceInstanceExtended service) {
    ServiceOperation lastServiceOperation = service.getLastOperation();
    return lastServiceOperation != null && lastServiceOperation.getState() == ServiceOperation.State.IN_PROGRESS;
}

19 Source : CheckServiceOperationStateStep.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected List<CloudServiceInstanceExtended> getExistingServicesInProgress(ProcessContext context) {
    CloudControllerClient client = context.getControllerClient();
    CloudServiceInstanceExtended serviceToProcess = context.getVariable(Variables.SERVICE_TO_PROCESS);
    CloudServiceInstanceExtended existingServiceInstance = getExistingService(client, serviceToProcess);
    if (existingServiceInstance == null || !isServiceOperationInProgress(existingServiceInstance)) {
        return Collections.emptyList();
    }
    return List.of(existingServiceInstance);
}

18 Source : UpdateServiceMetadataStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

@Test
void testUpdateServiceMetadata() {
    CloudServiceInstanceExtended serviceToProcess = buildServiceToProcess();
    prepareServiceToProcess(serviceToProcess);
    prepareClient(serviceToProcess);
    step.execute(execution);
    verify(client).updateServiceInstanceMetadata(serviceToProcess.getMetadata().getGuid(), serviceToProcess.getV3Metadata());
}

18 Source : UpdateServiceKeysStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private List<CloudServiceKey> buildServiceKeys(List<String> serviceKeysNames, List<String> updatedServiceKeys, CloudServiceInstanceExtended service) {
    return serviceKeysNames.stream().map(serviceKeyName -> buildCloudServiceKey(service, updatedServiceKeys, serviceKeyName)).collect(Collectors.toList());
}

18 Source : PollServiceOperationsStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

@SuppressWarnings("unchecked")
private void prepareServiceOperationGetter() {
    for (Entry<String, Object> response : input.serviceInstanceResponse.entrySet()) {
        Map<String, Object> serviceInstanceResponse = (Map<String, Object>) response.getValue();
        if (serviceInstanceResponse == null) {
            continue;
        }
        Map<String, Object> serviceOperationAsMap = (Map<String, Object>) serviceInstanceResponse.get("last_operation");
        CloudServiceInstanceExtended service = getCloudServiceExtended(response);
        ServiceOperation lastOp = new ServiceOperation(ServiceOperation.Type.fromString((String) serviceOperationAsMap.get("type")), (String) serviceOperationAsMap.get("description"), ServiceOperation.State.fromString((String) serviceOperationAsMap.get("state")));
        when(serviceOperationGetter.getLastServiceOperation(any(), eq(service))).thenReturn(lastOp);
    }
}

18 Source : CheckServiceOperationStateStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

protected void prepareContext(CloudServiceInstanceExtended service) {
    context.setVariable(Variables.SPACE_GUID, TEST_SPACE_ID);
    context.setVariable(Variables.SERVICE_TO_PROCESS, service);
}

18 Source : CheckServiceOperationStateStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private void prepareClient(CloudServiceInstanceExtended service, ServiceOperation serviceOperation, boolean serviceExist) {
    if (serviceExist) {
        CloudServiceInstanceExtended returnedService = ImmutableCloudServiceInstanceExtended.builder().from(service).lastOperation(serviceOperation).build();
        when(client.getServiceInstance(service.getName(), false)).thenReturn(returnedService);
    }
}

18 Source : ServiceBindingParametersGetter.java
with Apache License 2.0
from cloudfoundry-incubator

private Map<String, Object> getFileProvidedBindingParameters(String moduleName, CloudServiceInstanceExtended service) throws FileStorageException {
    String requiredDependencyName = NameUtil.getPrefixedName(moduleName, service.getResourceName(), org.cloudfoundry.multiapps.controller.core.Constants.MTA_ELEMENT_SEPARATOR);
    return getFileProvidedBindingParameters(requiredDependencyName);
}

18 Source : UpdateServicePlanStep.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected MethodExecution<String> executeOperation(ProcessContext context, CloudControllerClient client, CloudServiceInstanceExtended service) {
    if (service.shouldSkipPlanUpdate()) {
        getStepLogger().warn(Messages.WILL_NOT_UPDATE_SERVICE_PLAN, service.getName());
        return new MethodExecution<>(null, MethodExecution.ExecutionState.FINISHED);
    }
    getStepLogger().debug(Messages.UPDATING_SERVICE_0_WITH_PLAN_1, service.getName(), service.getPlan());
    client.updateServicePlan(service.getName(), service.getPlan());
    getStepLogger().debug(Messages.SERVICE_PLAN_FOR_SERVICE_0_UPDATED, service.getName());
    return new MethodExecution<>(null, MethodExecution.ExecutionState.EXECUTING);
}

18 Source : UpdateServiceParametersStep.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected MethodExecution<String> executeOperation(ProcessContext context, CloudControllerClient client, CloudServiceInstanceExtended service) {
    if (service.shouldSkipParametersUpdate()) {
        getStepLogger().warn(Messages.WILL_NOT_UPDATE_SERVICE_PARAMS, service.getName());
        return new MethodExecution<>(null, MethodExecution.ExecutionState.FINISHED);
    }
    getStepLogger().info(Messages.UPDATING_SERVICE, service.getName());
    client.updateServiceParameters(service.getName(), service.getCredentials());
    getStepLogger().debug(Messages.SERVICE_UPDATED, service.getName());
    return new MethodExecution<>(null, MethodExecution.ExecutionState.EXECUTING);
}

18 Source : PollServiceOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

protected ServiceOperation mapOperationState(StepLogger stepLogger, ServiceOperation lastServiceOperation, CloudServiceInstanceExtended service) {
    if (lastServiceOperation.getDescription() == null && lastServiceOperation.getState() == ServiceOperation.State.FAILED) {
        return new ServiceOperation(lastServiceOperation.getType(), Messages.DEFAULT_FAILED_OPERATION_DESCRIPTION, lastServiceOperation.getState());
    }
    return lastServiceOperation;
}

18 Source : PollServiceInProgressOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected void reportServiceState(ProcessContext context, CloudServiceInstanceExtended service, ServiceOperation lastServiceOperation) {
    if (lastServiceOperation.getState() == ServiceOperation.State.FAILED) {
        throw new SLException(getFailureMessage(service, lastServiceOperation));
    }
    if (lastServiceOperation.getState() == ServiceOperation.State.SUCCEEDED) {
        context.getStepLogger().debug(getSuccessMessage(service, lastServiceOperation.getType()));
    }
}

18 Source : PollServiceDeleteOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected void handleMissingOperationState(StepLogger stepLogger, CloudServiceInstanceExtended service) {
    throw new SLException(Messages.CANNOT_RETRIEVE_INSTANCE_OF_SERVICE, service.getName());
}

18 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private void setServiceParameters(ProcessContext context, CloudServiceInstanceExtended service) throws FileStorageException {
    service = prepareServiceParameters(context, service);
    context.setVariable(Variables.SERVICE_TO_PROCESS, service);
}

18 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean shouldUpdateTags(CloudServiceInstanceExtended service, List<String> existingServiceTags) {
    if (service.isUserProvided()) {
        return false;
    }
    existingServiceTags = ObjectUtils.defaultIfNull(existingServiceTags, Collections.emptyList());
    return !existingServiceTags.equals(service.getTags());
}

18 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean haveDifferentTypesOrLabels(CloudServiceInstanceExtended service, CloudServiceInstance existingService) {
    boolean haveDifferentTypes = service.isUserProvided() ^ existingService.isUserProvided();
    if (existingService.isUserProvided()) {
        return haveDifferentTypes;
    }
    boolean haveDifferentLabels = !Objects.equals(service.getLabel(), existingService.getLabel());
    return haveDifferentTypes || haveDifferentLabels;
}

18 Source : CreateServiceStep.java
with Apache License 2.0
from cloudfoundry-incubator

private boolean serviceExists(CloudServiceInstanceExtended cloudServiceExtended, CloudControllerClient client) {
    return client.getServiceInstance(cloudServiceExtended.getName(), false) != null;
}

18 Source : CreateServiceStep.java
with Apache License 2.0
from cloudfoundry-incubator

private MethodExecution<String> createManagedServiceInstance(CloudControllerClient client, CloudServiceInstanceExtended service) {
    return serviceCreatorFactory.createInstance(getStepLogger()).createService(client, service);
}

18 Source : ServiceWithAlternativesCreator.java
with Apache License 2.0
from cloudfoundry-incubator

private List<String> computePossibleServiceOfferings(CloudServiceInstanceExtended serviceInstance) {
    List<String> possibleServiceOfferings = new LinkedList<>(serviceInstance.getAlternativeLabels());
    possibleServiceOfferings.add(0, serviceInstance.getLabel());
    return possibleServiceOfferings;
}

18 Source : ServiceWithAlternativesCreator.java
with Apache License 2.0
from cloudfoundry-incubator

private void replacedertServiceAttributes(CloudServiceInstanceExtended service) {
    replacedert.notNull(service, "Service must not be null");
    replacedert.notNull(service.getName(), "Service name must not be null");
    replacedert.notNull(service.getLabel(), "Service label must not be null");
    replacedert.notNull(service.getPlan(), "Service plan must not be null");
}

18 Source : ServiceWithAlternativesCreator.java
with Apache License 2.0
from cloudfoundry-incubator

private List<CloudServicePlan> mergeServicePlans(CloudServiceInstanceExtended serviceInstance, List<CloudServicePlan> v1Plans, List<CloudServicePlan> v2Plans) {
    String servicePlanName = serviceInstance.getPlan();
    if (v1Plans.isEmpty() || v2Plans.isEmpty()) {
        String label = serviceInstance.getLabel();
        String broker = serviceInstance.getBroker();
        throw new SLException(Messages.EMPTY_SERVICE_PLANS_LIST_FOUND, label, broker, servicePlanName);
    }
    if (containsPlan(v1Plans, servicePlanName)) {
        return v1Plans;
    }
    if (containsPlan(v2Plans, servicePlanName)) {
        return v2Plans;
    }
    return v1Plans;
}

18 Source : ServiceWithAlternativesCreator.java
with Apache License 2.0
from cloudfoundry-incubator

private MethodExecution<String> createServiceInternal(CloudControllerClient client, CloudServiceInstanceExtended serviceInstance) {
    client.createServiceInstance(serviceInstance);
    return new MethodExecution<>(null, MethodExecution.ExecutionState.EXECUTING);
}

17 Source : ServiceBindingParametersGetterTest.java
with Apache License 2.0
from cloudfoundry-incubator

@Test
void testThrowingExceptionWhenServiceBindingIsMissing() {
    CloudApplication application = buildApplication(null);
    CloudServiceInstanceExtended serviceInstance = buildServiceInstance();
    prepareContext(serviceInstance);
    prepareClient(null, false);
    replacedertThrows(CloudOperationException.clreplaced, () -> serviceBindingParametersGetter.getServiceBindingParametersFromExistingInstance(application, SERVICE_NAME));
}

17 Source : UpdateServiceKeysStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private void prepareContext(List<CloudServiceKey> serviceKeys, boolean canDeleteServiceKeys, CloudServiceInstanceExtended service) {
    context.setVariable(Variables.SERVICE_KEYS_TO_CREATE, Map.of(SERVICE_NAME, serviceKeys));
    context.setVariable(Variables.DELETE_SERVICE_KEYS, canDeleteServiceKeys);
    context.setVariable(Variables.SERVICE_TO_PROCESS, service);
}

17 Source : UpdateServiceKeysStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

private ImmutableCloudServiceKey buildCloudServiceKey(CloudServiceInstanceExtended service, List<String> updatedServiceKeys, String serviceKeyName) {
    if (updatedServiceKeys.contains(serviceKeyName)) {
        return ImmutableCloudServiceKey.builder().name(serviceKeyName).serviceInstance(service).credentials(Map.of("name", "new-value")).build();
    }
    return ImmutableCloudServiceKey.builder().name(serviceKeyName).serviceInstance(service).build();
}

17 Source : UpdateServiceKeysStepTest.java
with Apache License 2.0
from cloudfoundry-incubator

@ParameterizedTest
@MethodSource
void testCreateUpdateServiceKeysStep(List<String> serviceKeysNames, List<String> existingServiceKeysNames, boolean canDeleteServiceKeys, List<String> updatedServiceKeys) {
    CloudServiceInstanceExtended service = buildService();
    List<CloudServiceKey> serviceKeys = buildServiceKeys(serviceKeysNames, updatedServiceKeys, service);
    List<CloudServiceKey> existingServiceKeys = buildServiceKeys(existingServiceKeysNames, Collections.emptyList(), service);
    prepareContext(serviceKeys, canDeleteServiceKeys, service);
    prepareServiceOperationExecutor(existingServiceKeys);
    step.execute(execution);
    verifyCreateCalls(serviceKeysNames, existingServiceKeysNames);
    verifyDeleteCalls(serviceKeysNames, existingServiceKeysNames, canDeleteServiceKeys);
    verifyUpdateCalls(updatedServiceKeys, canDeleteServiceKeys);
    replacedertStepFinishedSuccessfully();
}

17 Source : UpdateServiceTagsStep.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected MethodExecution<String> executeOperation(ProcessContext context, CloudControllerClient client, CloudServiceInstanceExtended service) {
    if (service.shouldSkipTagsUpdate()) {
        getStepLogger().warn(Messages.WILL_NOT_UPDATE_SERVICE_TAGS, service.getName());
        return new MethodExecution<>(null, MethodExecution.ExecutionState.FINISHED);
    }
    getStepLogger().info(Messages.UPDATING_SERVICE_TAGS, service.getName());
    client.updateServiceTags(service.getName(), service.getTags());
    getStepLogger().debug(Messages.SERVICE_TAGS_UPDATED, service.getName());
    return new MethodExecution<>(null, MethodExecution.ExecutionState.EXECUTING);
}

17 Source : UpdateServiceMetadataExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
public String getPollingErrorMessage(ProcessContext context) {
    CloudServiceInstanceExtended serviceInstance = context.getVariable(Variables.SERVICE_TO_PROCESS);
    return MessageFormat.format(Messages.ERROR_UPDATING_METADATA_OF_SERVICE_INSTANCE_0, serviceInstance.getName());
}

17 Source : ServiceStep.java
with Apache License 2.0
from cloudfoundry-incubator

private MethodExecution<String> executeOperationAndHandleExceptions(ProcessContext context, CloudServiceInstanceExtended service) {
    try {
        return executeOperation(context, context.getControllerClient(), service);
    } catch (CloudOperationException e) {
        String serviceUpdateFailedMessage = MessageFormat.format(Messages.FAILED_SERVICE_UPDATE, service.getName(), e.getStatusText());
        throw new CloudOperationException(e.getStatusCode(), serviceUpdateFailedMessage, e.getDescription(), e);
    }
}

17 Source : PollServiceOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

private ServiceOperation getLastServiceOperationAndHandleExceptions(ProcessContext context, CloudServiceInstanceExtended service) {
    try {
        ServiceOperation lastServiceOperation = getLastServiceOperation(context, service);
        if (lastServiceOperation != null) {
            return mapOperationState(context.getStepLogger(), lastServiceOperation, service);
        }
        handleMissingOperationState(context.getStepLogger(), service);
        return null;
    } catch (CloudOperationException e) {
        String errorMessage = format(Messages.ERROR_POLLING_OF_SERVICE, service.getName(), e.getStatusText());
        throw new CloudControllerException(e.getStatusCode(), errorMessage, e.getDescription());
    }
}

17 Source : PollServiceDeleteOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

private String getSuccessMessage(CloudServiceInstanceExtended service) {
    return MessageFormat.format(Messages.SERVICE_DELETED, service.getName());
}

17 Source : PollServiceCreateOrUpdateOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

private void handleFailedState(StepLogger stepLogger, CloudServiceInstanceExtended service, ServiceOperation lastServiceOperation) {
    if (shouldFail(service)) {
        throw new SLException(getFailureMessage(service, lastServiceOperation));
    }
    stepLogger.warn(getWarningMessage(service, lastServiceOperation));
}

17 Source : PollServiceCreateOrUpdateOperationsExecution.java
with Apache License 2.0
from cloudfoundry-incubator

@Override
protected void reportServiceState(ProcessContext context, CloudServiceInstanceExtended service, ServiceOperation lastServiceOperation) {
    if (lastServiceOperation.getState() == ServiceOperation.State.SUCCEEDED) {
        context.getStepLogger().debug(getSuccessMessage(service, lastServiceOperation.getType()));
        return;
    }
    if (lastServiceOperation.getState() == ServiceOperation.State.FAILED) {
        handleFailedState(context.getStepLogger(), service, lastServiceOperation);
    }
}

17 Source : DetermineServiceCreateUpdateServiceActionsStep.java
with Apache License 2.0
from cloudfoundry-incubator

private CloudServiceInstanceExtended setServiceParameters(ProcessContext context, CloudServiceInstanceExtended service, String fileName) throws FileStorageException {
    String appArchiveId = context.getRequiredVariable(Variables.APP_ARCHIVE_ID);
    String spaceGuid = context.getVariable(Variables.SPACE_GUID);
    return fileService.processFileContent(spaceGuid, appArchiveId, appArchiveStream -> {
        try (InputStream is = ArchiveHandler.getInputStream(appArchiveStream, fileName, configuration.getMaxManifestSize())) {
            return mergeCredentials(service, is);
        } catch (IOException e) {
            throw new SLException(e, Messages.ERROR_RETRIEVING_MTA_RESOURCE_CONTENT, fileName);
        }
    });
}

See More Examples