Search in sources :

Example 1 with PromotionEntity

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);
}
Also used : BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with PromotionEntity

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();
}
Also used : BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 3 with PromotionEntity

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");
}
Also used : BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) Test(org.junit.Test)

Example 4 with PromotionEntity

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;
}
Also used : PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity)

Example 5 with 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;
}
Also used : PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityAuthor(io.gravitee.rest.api.model.promotion.PromotionEntityAuthor)

Aggregations

PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)18 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)6 PromotionEntityAuthor (io.gravitee.rest.api.model.promotion.PromotionEntityAuthor)6 PromotionEntityStatus (io.gravitee.rest.api.model.promotion.PromotionEntityStatus)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Page (io.gravitee.common.data.domain.Page)5 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)5 TaskEntity (io.gravitee.rest.api.model.TaskEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 CREATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE)5 UPDATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE)5 ApiService (io.gravitee.rest.api.service.ApiService)5 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)5 PermissionService (io.gravitee.rest.api.service.PermissionService)5 PromotionService (io.gravitee.rest.api.service.promotion.PromotionService)5 PromotionTasksService (io.gravitee.rest.api.service.promotion.PromotionTasksService)5 java.util (java.util)5 Collections.emptyList (java.util.Collections.emptyList)5