Search in sources :

Example 1 with ContinuousDeliveryEnvironment

use of io.syndesis.common.model.integration.ContinuousDeliveryEnvironment in project syndesis by syndesisio.

the class PublicApiHandlerTest method testPatchTagsForRelease.

@Test
public void testPatchTagsForRelease() throws Exception {
    final DataManager dataManager = mock(DataManager.class);
    final Environment env1 = newEnvironment("env1");
    when(dataManager.fetchByPropertyValue(Environment.class, "name", "env1")).thenReturn(Optional.of(env1));
    when(dataManager.fetch(Environment.class, env1.getId().get())).thenReturn(env1);
    final Environment env2 = newEnvironment("env2");
    when(dataManager.fetchByPropertyValue(Environment.class, "name", "env2")).thenReturn(Optional.of(env2));
    when(dataManager.fetch(Environment.class, env2.getId().get())).thenReturn(env2);
    @SuppressWarnings("JdkObsolete") final Date epoh = new Date(0);
    final ContinuousDeliveryEnvironment existingContinuousDeliveryEntry = new ContinuousDeliveryEnvironment.Builder().environmentId(env1.getId().get()).lastTaggedAt(epoh).build();
    final Integration integration = new Integration.Builder().putContinuousDeliveryState(env1.getId().get(), existingContinuousDeliveryEntry).build();
    when(dataManager.fetch(Integration.class, "integration-id")).thenReturn(integration);
    final EnvironmentHandler environmentHandler = new EnvironmentHandler(dataManager);
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(null, null, null, null, null, environmentHandler, null, null);
    final Map<String, ContinuousDeliveryEnvironment> continuousDeliveryEnvironment = handler.patchTagsForRelease("integration-id", Collections.singletonList("env2"));
    assertThat(continuousDeliveryEnvironment).containsEntry("env1", existingContinuousDeliveryEntry);
    assertThat(continuousDeliveryEnvironment).hasEntrySatisfying("env2", containsContinuousDeliveryEntry());
    assertThat(continuousDeliveryEnvironment.get("env1").getLastTaggedAt()).isBefore(continuousDeliveryEnvironment.get("env2").getLastTaggedAt());
    verify(dataManager).update(integration.builder().putContinuousDeliveryState(env2.getId().get(), continuousDeliveryEnvironment.get("env2")).build());
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) DataManager(io.syndesis.server.dao.manager.DataManager) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ContinuousDeliveryEnvironment

use of io.syndesis.common.model.integration.ContinuousDeliveryEnvironment in project syndesis by syndesisio.

the class PublicApiHandlerTest method testPutTagsForRelease.

@Test
public void testPutTagsForRelease() throws Exception {
    final Environment environment = newEnvironment("env");
    final Integration integration = new Integration.Builder().build();
    final DataManager dataManager = mock(DataManager.class);
    when(dataManager.fetchByPropertyValue(Environment.class, "name", "env")).thenReturn(Optional.of(environment));
    when(dataManager.fetch(Environment.class, environment.getId().get())).thenReturn(environment);
    when(dataManager.fetch(Integration.class, "integration-id")).thenReturn(integration);
    final EnvironmentHandler environmentHandler = new EnvironmentHandler(dataManager);
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(null, null, null, null, null, environmentHandler, null, null);
    final Map<String, ContinuousDeliveryEnvironment> continuousDeliveryEnvironment = handler.putTagsForRelease("integration-id", Collections.singletonList("env"));
    assertThat(continuousDeliveryEnvironment).hasEntrySatisfying("env", containsContinuousDeliveryEntry());
    verify(dataManager).update(integration.builder().putContinuousDeliveryState(environment.getId().get(), continuousDeliveryEnvironment.get("env")).build());
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) DataManager(io.syndesis.server.dao.manager.DataManager) Test(org.junit.Test)

Example 3 with ContinuousDeliveryEnvironment

use of io.syndesis.common.model.integration.ContinuousDeliveryEnvironment in project syndesis by syndesisio.

the class PublicApiHandlerTest method testGetReleaseTags.

@Test
public void testGetReleaseTags() {
    final DataManager dataManager = mock(DataManager.class);
    final Environment env = newEnvironment("env");
    final String envId = env.getId().get();
    final ContinuousDeliveryEnvironment deliveryEnvironment = new ContinuousDeliveryEnvironment.Builder().environmentId(envId).build();
    final Integration integration = new Integration.Builder().putContinuousDeliveryState(envId, deliveryEnvironment).build();
    when(dataManager.fetch(Integration.class, "integration-id")).thenReturn(integration);
    when(dataManager.fetch(Environment.class, envId)).thenReturn(env);
    final EnvironmentHandler environmentHandler = new EnvironmentHandler(dataManager);
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(null, null, null, null, null, environmentHandler, null, null);
    final Map<String, ContinuousDeliveryEnvironment> releaseTags = handler.getReleaseTags("integration-id");
    assertThat(releaseTags).containsOnly(entry("env", deliveryEnvironment));
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) DataManager(io.syndesis.server.dao.manager.DataManager) Test(org.junit.Test)

Example 4 with ContinuousDeliveryEnvironment

use of io.syndesis.common.model.integration.ContinuousDeliveryEnvironment in project syndesis by syndesisio.

the class EnvironmentHandler method deleteEnvironment.

/**
 * Delete an environment across all integrations.
 */
@DELETE
@Path("{env}")
public void deleteEnvironment(@NotNull @PathParam("env") @Parameter(required = true) String environment) {
    validateEnvironment(ENVIRONMENT, environment);
    final DataManager dataManager = getDataManager();
    final String envId = getEnvironment(environment).getId().orElse(null);
    // get and update list of integrations with this environment
    final List<Integration> integrations = dataManager.fetchAll(Integration.class).getItems().stream().filter(i -> i.getContinuousDeliveryState().containsKey(envId)).map(i -> {
        final Map<String, ContinuousDeliveryEnvironment> state = new HashMap<>(i.getContinuousDeliveryState());
        // untag
        state.remove(envId);
        return i.builder().continuousDeliveryState(state).build();
    }).collect(Collectors.toList());
    // update integrations using this environment name
    integrations.forEach(dataManager::update);
    // delete the environment
    dataManager.delete(Environment.class, envId);
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Date(java.util.Date) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Function(java.util.function.Function) ClientErrorException(javax.ws.rs.ClientErrorException) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) ArrayList(java.util.ArrayList) Environment(io.syndesis.common.model.environment.Environment) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DataManager(io.syndesis.server.dao.manager.DataManager) PATCH(javax.ws.rs.PATCH) Integration(io.syndesis.common.model.integration.Integration) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Parameter(io.swagger.v3.oas.annotations.Parameter) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) PUT(javax.ws.rs.PUT) Pattern(java.util.regex.Pattern) BaseHandler(io.syndesis.server.endpoint.v1.handler.BaseHandler) Integration(io.syndesis.common.model.integration.Integration) DataManager(io.syndesis.server.dao.manager.DataManager) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with ContinuousDeliveryEnvironment

use of io.syndesis.common.model.integration.ContinuousDeliveryEnvironment in project syndesis by syndesisio.

the class EnvironmentHandler method tagForRelease.

private Map<String, ContinuousDeliveryEnvironment> tagForRelease(String integrationId, List<String> environments, boolean deleteOtherTags) {
    if (environments == null) {
        throw new ClientErrorException("Missing parameter environments", Response.Status.BAD_REQUEST);
    }
    // validate individual environment names
    final List<String> ids = environments.stream().map(e -> getEnvironment(e).getId().get()).collect(Collectors.toList());
    // fetch integration
    final Integration integration = getIntegration(integrationId);
    final HashMap<String, ContinuousDeliveryEnvironment> deliveryState = new HashMap<>(integration.getContinuousDeliveryState());
    @SuppressWarnings("JdkObsolete") Date lastTaggedAt = new Date();
    for (String envId : ids) {
        // create or update tag
        deliveryState.put(envId, createOrUpdateTag(deliveryState, envId, lastTaggedAt));
    }
    // delete tags not in the environments list?
    final Set<String> keySet = deliveryState.keySet();
    if (deleteOtherTags) {
        keySet.retainAll(ids);
    }
    // update json db
    getDataManager().update(integration.builder().continuousDeliveryState(deliveryState).build());
    LOG.debug("Tagged integration {} for environments {} at {}", integrationId, environments, lastTaggedAt);
    return getNamedDeliveryState(deliveryState);
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Date(java.util.Date) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Function(java.util.function.Function) ClientErrorException(javax.ws.rs.ClientErrorException) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) ArrayList(java.util.ArrayList) Environment(io.syndesis.common.model.environment.Environment) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DataManager(io.syndesis.server.dao.manager.DataManager) PATCH(javax.ws.rs.PATCH) Integration(io.syndesis.common.model.integration.Integration) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Parameter(io.swagger.v3.oas.annotations.Parameter) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) PUT(javax.ws.rs.PUT) Pattern(java.util.regex.Pattern) BaseHandler(io.syndesis.server.endpoint.v1.handler.BaseHandler) Integration(io.syndesis.common.model.integration.Integration) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) HashMap(java.util.HashMap) ClientErrorException(javax.ws.rs.ClientErrorException) Date(java.util.Date)

Aggregations

ContinuousDeliveryEnvironment (io.syndesis.common.model.integration.ContinuousDeliveryEnvironment)9 Environment (io.syndesis.common.model.environment.Environment)8 Integration (io.syndesis.common.model.integration.Integration)8 DataManager (io.syndesis.server.dao.manager.DataManager)7 EnvironmentHandler (io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 DELETE (javax.ws.rs.DELETE)4 Path (javax.ws.rs.Path)4 Parameter (io.swagger.v3.oas.annotations.Parameter)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 BaseHandler (io.syndesis.server.endpoint.v1.handler.BaseHandler)2 Optional (java.util.Optional)2 Set (java.util.Set)2