use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.
the class PromoteApiOperationHandler method handle.
@Override
public Single<BridgeReply> handle(BridgeCommand bridgeCommand) {
BridgeSimpleReply reply = new BridgeSimpleReply();
reply.setCommandId(bridgeCommand.getId());
final PromotionEntity promotionEntity;
try {
promotionEntity = objectMapper.readValue(bridgeCommand.getPayload().getContent(), PromotionEntity.class);
} catch (JsonProcessingException e) {
logger.warn("Problem while deserializing promotion request for environment {}", bridgeCommand.getEnvironmentId());
reply.setCommandStatus(CommandStatus.ERROR);
reply.setMessage("Problem while deserializing promotion request for environment [" + bridgeCommand.getEnvironmentId() + "]");
return Single.just(reply);
}
promotionEntity.setStatus(PromotionEntityStatus.TO_BE_VALIDATED);
PromotionEntity promotion = promotionService.createOrUpdate(promotionEntity);
reply.setCommandStatus(CommandStatus.SUCCEEDED);
reply.setOrganizationId(bridgeCommand.getOrganizationId());
reply.setEnvironmentId(bridgeCommand.getTarget().getEnvironmentId());
reply.setInstallationId(installationService.get().getId());
try {
reply.setPayload(objectMapper.writeValueAsString(promotion));
} catch (JsonProcessingException e) {
logger.warn("Problem while serializing promotion request for environment {}", promotion.getId());
reply.setCommandStatus(CommandStatus.ERROR);
reply.setMessage("Problem while serializing promotion request for environment [" + bridgeCommand.getEnvironmentId() + "]");
return Single.just(reply);
}
return Single.just(reply);
}
use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.
the class CockpitServiceTest method shouldNotProcessPromotionCommandError.
@Test
public void shouldNotProcessPromotionCommandError() {
BridgeReply reply = new BridgeSimpleReply();
reply.setCommandStatus(CommandStatus.ERROR);
when(cockpitCommandService.send(any())).thenReturn(reply);
final CockpitReply<PromotionEntity> result = cockpitService.processPromotion(new PromotionEntity());
assertThat(result).isNotNull();
assertThat(result.getStatus()).isEqualTo(CockpitReplyStatus.ERROR);
final PromotionEntity entity = result.getReply();
assertThat(entity).isNull();
}
use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.
the class BridgeCommandFactoryTest method shouldCreatePromoteApiCommand.
@Test
public void shouldCreatePromoteApiCommand() {
PromotionEntity promotionEntity = new PromotionEntity();
promotionEntity.setTargetEnvCockpitId("env#target");
final BridgeCommand promoteApiCommand = bridgeCommandFactory.createPromoteApiCommand("env#target", "{ \"id\": \"test\"}");
assertThat(promoteApiCommand).isNotNull();
assertThat(promoteApiCommand.getEnvironmentId()).isEqualTo(ENVIRONMENT_ID);
assertThat(promoteApiCommand.getOrganizationId()).isEqualTo(ORGANIZATION_ID);
assertThat(promoteApiCommand.getInstallationId()).isEqualTo(INSTALLATION_ID);
assertThat(promoteApiCommand.getOperation()).isEqualTo(BridgeOperation.PROMOTE_API.name());
assertThat(promoteApiCommand.getPayload().getContent()).isEqualTo("{ \"id\": \"test\"}");
final BridgeTarget bridgeTarget = promoteApiCommand.getTarget();
assertThat(bridgeTarget.getEnvironmentId()).isEqualTo("env#target");
}
use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.
the class PromoteApiOperationHandlerTest method getAPromotionEntity.
private PromotionEntity getAPromotionEntity() {
final PromotionEntity promotionEntity = new PromotionEntity();
promotionEntity.setSourceEnvCockpitId("sourceEnvId");
promotionEntity.setTargetEnvCockpitId("targetEnvId");
promotionEntity.setApiDefinition("definition");
promotionEntity.setStatus(PromotionEntityStatus.TO_BE_VALIDATED);
return promotionEntity;
}
use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.
the class GoodbyeCommandHandlerTest method getAPromotionEntity.
private PromotionEntity getAPromotionEntity(String id) {
final PromotionEntity promotion = new PromotionEntity();
promotion.setApiDefinition("{\"id\" : \"api#1\",\"name\" : \"API Name\",\"version\" : \"1\",\"proxy\" : { \"context_path\" : \"/product\", \"endpoint\" : \"http://toto.com\", \"endpoints\" : [ { \"target\" : \"http://toto.com\", \"weight\" : 1, \"name\" : \"endpointName\" } ], \"strip_context_path\" : false, \"http\" : { \"configuration\" : { \"connectTimeout\" : 5000, \"idleTimeout\" : 60000, \"keepAlive\" : true, \"dumpRequest\" : false } }},\"paths\" : { \"/\" : [ { \"methods\" : [ ], \"api-key\" : {} } ]},\"tags\" : [ ]\n}");
promotion.setTargetEnvCockpitId("env#1-cockpit-id");
promotion.setTargetEnvName("Target Env");
promotion.setSourceEnvCockpitId("env#2-cockpit-id");
promotion.setSourceEnvName("Source Env");
promotion.setApiId("api id");
promotion.setTargetApiId("target api id");
promotion.setStatus(PromotionEntityStatus.TO_BE_VALIDATED);
promotion.setId(id);
PromotionEntityAuthor author = new PromotionEntityAuthor();
author.setDisplayName("Author");
author.setEmail("author@gv.io");
author.setPicture("https://picture.png");
promotion.setAuthor(author);
return promotion;
}
Aggregations