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());
}
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());
}
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));
}
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);
}
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);
}
Aggregations