Skip to content

Commit

Permalink
Implement static dashboard url (#47 step 2)
Browse files Browse the repository at this point in the history
Implement getinstance support in ProcessorChainServiceInstanceService
  • Loading branch information
gberche-orange committed May 25, 2020
1 parent 2163d8f commit ef442d3
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 13 deletions.
14 changes: 14 additions & 0 deletions TODO-coabc.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Implement static dashboard url (#47 step 2)

- implement the `GET /v2/service_instances/:instance_id`
- DefaultBrokerProcessor.preGetServiceInstance() +
- BoshProcessor.preGetServiceInstance() + BoshProcessorTest :
- Return dashboard previously recorded in `coab-vars.yml`
- BoshBrokerApplication.paasTemplateContextFilter:
- check whether other steps could skip paas-secrets clone

- for inner brokers not supporting this fetch endpoint, record dashboard returned from provisionning call in git secrets git repo: in `coab-vars.yml`

- return `instances_retrievable` in [catalog service offering object](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#service-offering-object)

--

Dependency bumps
* [ ] clean up duplicated WireMockTestFixture and WireMockTestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public BrokerProcessor paasTemplateContextFilter(PipelineProperties pipelineProp
public void preUnBind(Context ctx) { skipPaasTemplateGitCloneAndPush(ctx); }
@Override
public void preUpdate(Context ctx) { skipPaasTemplateGitCloneAndPush(ctx); }
@Override
public void preGetInstance(Context ctx) { skipPaasTemplateGitCloneAndPush(ctx); }

private void registerPaasTemplatesBranches(Context ctx) {
ctx.contextKeys.put(TEMPLATES_REPOSITORY_ALIAS_NAME + GitProcessorContext.checkOutRemoteBranch.toString(), pipelineProperties.getCheckOutRemoteBranch()); //"develop"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition;
import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest;
import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest;
import org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceRequest;
import org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceRequest;

import java.util.Collections;
Expand All @@ -30,7 +31,7 @@ public class OsbBuilderHelper {
@SuppressWarnings("WeakerAccess")
public static DeleteServiceInstanceBindingRequest anUnbindRequest(String serviceInstanceId, String bindingId) {
ServiceDefinition serviceDefinition = aCatalog().getServiceDefinitions().get(0);
DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
return DeleteServiceInstanceBindingRequest.builder()
.serviceDefinition(serviceDefinition)
.bindingId(bindingId)
.serviceDefinitionId(SERVICE_DEFINITION_ID)
Expand All @@ -39,7 +40,6 @@ public static DeleteServiceInstanceBindingRequest anUnbindRequest(String service
.apiInfoLocation("api-info")
.originatingIdentity(aCfUserContext())
.platformInstanceId("cf-instance-id").build();
return request;
}

public static Catalog aCatalog() {
Expand Down Expand Up @@ -76,7 +76,7 @@ public static CreateServiceInstanceBindingRequest aBindingRequest(String service

Context cfContext = aCfContext();

CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
return CreateServiceInstanceBindingRequest.builder()
.serviceDefinitionId(SERVICE_DEFINITION_ID)
.planId(SERVICE_PLAN_ID)
.bindResource(bindResource)
Expand All @@ -88,7 +88,6 @@ public static CreateServiceInstanceBindingRequest aBindingRequest(String service
.originatingIdentity(aCfUserContext())
.platformInstanceId("cf-instance-id")
.build();
return request;
}

public static Context aCfContext() {
Expand Down Expand Up @@ -160,4 +159,10 @@ public static UpdateServiceInstanceRequest anUpdateServiceInstanceRequest() {
.serviceInstanceId("instance_id")
.build();
}

public static GetServiceInstanceRequest aGetServiceInstanceRequest() {
return GetServiceInstanceRequest.builder()
.serviceInstanceId("instance_id")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ProcessorChainServiceInstanceService implements ServiceInstanceServ
private static Logger logger = LoggerFactory.getLogger(ProcessorChainServiceInstanceService.class.getName());


public static final String GET_SERVICE_INSTANCE_REQUEST = "GetServiceInstanceRequest";
public static final String CREATE_SERVICE_INSTANCE_REQUEST = "CreateServiceInstanceRequest";
public static final String CREATE_SERVICE_INSTANCE_RESPONSE = "CreateServiceInstanceResponse";
public static final String GET_LAST_SERVICE_OPERATION_REQUEST = "GetLastServiceOperationRequest";
Expand Down Expand Up @@ -62,6 +63,26 @@ public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstance
}
}

@Override
public GetServiceInstanceResponse getServiceInstance(GetServiceInstanceRequest request) {
try {
Context ctx=new Context();
ctx.contextKeys.put(GET_SERVICE_INSTANCE_REQUEST, request);
processorChain.create(ctx);

GetServiceInstanceResponse response;
if (ctx.contextKeys.get(GET_SERVICE_INSTANCE_REQUEST) instanceof GetServiceInstanceRequest) {
response = (GetServiceInstanceResponse) ctx.contextKeys.get(GET_SERVICE_INSTANCE_REQUEST);
} else {
response = GetServiceInstanceResponse.builder().build();
}
return response;
} catch (RuntimeException e) {
logger.info("Unable to fetch service with request " + request + ", caught " + e, e);
throw ProcessorChainServiceHelper.processInternalException(e);
}
}

@Override
public UpdateServiceInstanceResponse updateServiceInstance(UpdateServiceInstanceRequest request) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ public void chains_update_processors_on_service_instance_update() {
Context ctx=argument.getValue();
assertThat(ctx.contextKeys.get(ProcessorChainServiceInstanceService.UPDATE_SERVICE_INSTANCE_REQUEST)).isEqualTo(request);

}
@Test
public void chains_get_processors_on_service_instance_get() {
//given
GetServiceInstanceRequest request = OsbBuilderHelper.aGetServiceInstanceRequest();
//when
GetServiceInstanceResponse response = service.getServiceInstance(request);

//then call is properly chained
ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
Assertions.assertThat(response).isEqualTo(GetServiceInstanceResponse.builder().build());
Mockito.verify(processorChain).getInstance(argument.capture());

//and context is populated with the request
Context ctx=argument.getValue();
assertThat(ctx.contextKeys.get(ProcessorChainServiceInstanceService.GET_SERVICE_INSTANCE_REQUEST)).isEqualTo(request);

}

@Test
Expand Down Expand Up @@ -251,6 +268,33 @@ public void preUpdate(Context ctx) {
Assertions.assertThat(response).isEqualTo(customResponse);
}

@Test
public void uses_getinstance_response_from_context_when_set() {
//given
GetServiceInstanceRequest request = OsbBuilderHelper.aGetServiceInstanceRequest();

//given a processor that generates a response into the context
final GetServiceInstanceResponse customResponse = GetServiceInstanceResponse.builder()
.dashboardUrl("dashboard")
.build();

BrokerProcessor processor = new DefaultBrokerProcessor() {
@Override
public void preGetInstance(Context ctx) {
ctx.contextKeys.put(ProcessorChainServiceInstanceService.GET_SERVICE_INSTANCE_REQUEST, customResponse);
}
};
processorChain = aProcessorChain(processor);
service = new ProcessorChainServiceInstanceService(processorChain);


//when
GetServiceInstanceResponse response = service.getServiceInstance(request);

//then
Assertions.assertThat(response).isEqualTo(customResponse);
}



public ProcessorChain aProcessorChain(BrokerProcessor processor) {
Expand All @@ -262,4 +306,4 @@ public ProcessorChain aProcessorChain(BrokerProcessor processor) {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public interface BrokerProcessor {
void postDelete(Context ctx);

void cleanUp(Context ctx);

void preGetInstance(Context ctx);
void postGetInstance(Context ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public interface BrokerSink {
void getLastOperation(Context ctx);
void bind(Context ctx);
void unBind(Context ctx);
void getInstance(Context ctx);
void update(Context ctx);

void delete(Context ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ public void postUnBind(Context ctx) {
}

@Override
public void preUpdate(Context ctx) {
logger.debug("noop default preUpdate");
}
public void preUpdate(Context ctx) { logger.debug("noop default preUpdate"); }

@Override
public void postUpdate(Context ctx) {
logger.debug("noop default postUpdate");
}

@Override
public void preGetInstance(Context ctx) { logger.debug("noop default preGetInstance"); }

@Override
public void postGetInstance(Context ctx) { logger.debug("noop default postGetInstance"); }

@Override
public void cleanUp(Context ctx) { logger.debug("noop default cleanUp"); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public void bind(Context ctx) {
logger.debug("noop default Bind");
}

@Override
public void getInstance(Context ctx) { logger.debug("noop default GetInstance"); }

@Override
public void delete(Context ctx) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.orange.oss.cloudfoundry.broker.opsautomation.ondemandbroker.processors;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;



public class ProcessorChain {
Expand Down Expand Up @@ -37,6 +37,24 @@ public void create(Context ctx) {
}
}
}
public void getInstance(Context ctx) {
try {
for (BrokerProcessor m : processors) {
m.preGetInstance(ctx);
}
sink.getInstance(ctx);

for (int i = processors.size() - 1; i >= 0; i--) {
BrokerProcessor m = processors.get(i);
m.postGetInstance(ctx);
}
} finally {
for (int i = processors.size() - 1; i >= 0; i--) {
BrokerProcessor m = processors.get(i);
m.cleanUp(ctx);
}
}
}

public void getLastOperation(Context ctx) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.orange.oss.cloudfoundry.broker.opsautomation.ondemandbroker.processors;

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;


public class ProcessorChainTest {

Expand Down Expand Up @@ -83,6 +83,16 @@ public void postUpdate(Context ctx) {
logger.info("post update 1");

}

@Override
public void preGetInstance(Context ctx) {
logger.info("pre getinstance 1");
}

@Override
public void postGetInstance(Context ctx) {
logger.info("post getinstance 1");
}
});

processors.add(new BrokerProcessor() {
Expand Down Expand Up @@ -114,6 +124,11 @@ public void postBind(Context ctx) {
logger.info("post Bind 2");
}

@Override
public void preGetInstance(Context ctx) { logger.info("pre getinstance 2"); }

@Override
public void postGetInstance(Context ctx) { logger.info("post getinstance 2"); }
@Override
public void preDelete(Context ctx) {
logger.info("pre delete 2");
Expand Down

0 comments on commit ef442d3

Please sign in to comment.