public String getName() { return integration.getName(); }
@Override public byte[] generatePom(Integration integration) throws IOException { final Set<MavenGav> dependencies = collectDependencies(integration).stream() .filter(Dependency::isMaven) .map(Dependency::getId) .map(MavenGav::new) .collect(Collectors.toCollection(TreeSet::new)); return generate( new PomContext( integration.getId().orElse(""), integration.getName(), integration.getDescription().orElse(null), dependencies, generatorProperties.getMavenProperties()), pomMustache ); }
public List<StepOverview> getSteps() { return integration.getSteps().stream().map(StepOverview::new).collect(Collectors.toList()); }
@SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.ExceptionAsFlowControl"}) protected void addSourceFiles(UriInfo uriInfo, ZipOutputStream os, String integrationName) { ListResult<Integration> list = integrationHandler.list(uriInfo); list.getItems().stream() .filter(integration -> integrationName.equalsIgnoreCase(integration.getName().replace(' ', '-'))) .map(integration -> integration.getId()) .forEach( integrationId -> { integrationId.ifPresent(id -> { try { addSource(integrationName, id, os); } catch (Exception e) { LOG.error("Error preparing logs for integration: {}", integrationName, e); } }); }); }
/** * Counts active integrations (in DB) of the owner of the specified integration. * * @param integration The specified integration. * @return The number of integrations (excluding the current). */ private int countActiveIntegrationsOfSameUserAs(Integration integration) { String integrationId = integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration.")); String username = integration.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems() .stream() .filter(i -> !i.getIntegrationId().get().equals(integrationId)) //The "current" integration will already be in the database. .filter(i -> IntegrationDeploymentState.Active == i.getCurrentState()) .map(i -> i.getIntegrationId().get()) .distinct() .map(i -> dataManager.fetch(Integration.class, i)) .filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)) .count(); }
private void importIntegrations(SecurityContext sec, JsonDbDao<Integration> export, ArrayList<ChangeEvent> result) { for (Integration integration : export.fetchAll().getItems()) { Integration.Builder builder = new Integration.Builder() .createFrom(integration) .isDeleted(false) .updatedAt(System.currentTimeMillis()); // Do we need to create it? String id = integration.getId().get(); Integration previous = dataManager.fetch(Integration.class, id); if (previous == null) { LOG.info("Creating integration: {}", integration.getName()); integrationHandler.create(sec, builder.build()); result.add(ChangeEvent.of("created", integration.getKind().getModelName(), id)); } else { LOG.info("Updating integration: {}", integration.getName()); integrationHandler.update(id, builder.version(previous.getVersion()+1).build()); result.add(ChangeEvent.of("updated", integration.getKind().getModelName(), id)); } integrationHandler.updateBulletinBoard(id); break; } }
@Test public void testTrimming() throws IOException { final SortedSet<String> tags = new TreeSet<>(); tags.add(""); tags.add(" tag"); tags.add("\tTaggy McTagface\t"); final Integration original = new Integration.Builder() .id("test") .name(" some-name\t").description("") .tags(tags) .desiredStatus(IntegrationDeploymentState.Draft) .build(); final Integration created = Json.mapper().readValue(Json.mapper().writeValueAsBytes(original), Integration.class); assertThat(created.getName()).isEqualTo("some-name"); assertThat(created.getDescription()).isNotPresent(); assertThat(created.getTags()).containsExactly("Taggy McTagface", "tag"); } }
@Override public Integration get(String id) { Integration integration = Getter.super.get(id); if ( integration.isDeleted() ) { //Not sure if we need to do that for both current and desired status, //but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why? //Cause that test, is using NoopHandlerProvider, so that means no controllers. throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId())); } // Get the latest connection configs. List<Connection> connections = integration.getConnections().stream() .map(this::toCurrentConnection) .collect(Collectors.toList()); List<Step> steps = integration.getSteps().stream() .map(this::toCurrentSteps) .collect(Collectors.toList()); return new Integration.Builder() .createFrom(integration) .connections(connections) .steps(steps) .build(); }
public Optional<String> getId() { return integration.getId(); }
ids = new ArrayList<>(); for (Integration integration : dataManager.fetchAll(Integration.class).getItems()) { ids.add(integration.getId().get()); Integration integration = integrationHandler.get(id); addToExport(memJsonDB, integration); resourceManager.collectDependencies(integration.getSteps()).stream() .filter(Dependency::isExtension) .map(Dependency::getId)
public Optional<String> getDescription() { return integration.getDescription(); }
public SortedSet<String> getTags() { return integration.getTags(); }
/** * Counts active integrations (in DB) of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of integrations (excluding the current). */ private int countActiveIntegrationsOfSameUserAs(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String integrationId = integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration.")); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems() .stream() .filter(i -> !i.getIntegrationId().get().equals(integrationId)) //The "current" integration will already be in the database. .filter(i -> IntegrationDeploymentState.Published == i.getCurrentState()) .filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)) .count(); }
/** * Count the deployments of the owner of the specified integration. * * @param integration The specified integration. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(Integration integration) { String id = Labels.sanitize(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String username = integration.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
@GET @Path("/delete-deployments") public void deleteDeployments() { LOG.warn("user {} is deleting all integration deploymets", context.getRemoteUser()); List<Integration> integrations = dataMgr.fetchAll(Integration.class).getItems(); for (Integration i : integrations) { if (openShiftService.exists(i.getName())) { openShiftService.delete(i.getName()); LOG.debug("Deleting integration \"{}\"", i.getName()); } else { LOG.debug("Skipping integration named \"{}\". No such deployment found.", i.getName()); } } }
/** * Count the deployments of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.sanitize(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
private boolean isIntegrationActiveAndUsingExtension(IntegrationDeployment integrationDeployment, Extension extension) { if (integrationDeployment == null || extension == null) { return false; } if (IntegrationDeploymentState.Published != integrationDeployment.getTargetState()) { return false; } return integrationDeployment.getSpec().getSteps().stream().anyMatch(step -> { boolean usedAsStep = extension.getExtensionId().equals( Optional.ofNullable(step) .flatMap(Step::getExtension) .map(Extension::getExtensionId) .orElse(null) ); boolean usedAsConnector = extension.getExtensionId().equals( Optional.ofNullable(step) .flatMap(Step::getConnection) .flatMap(Connection::getConnector) .flatMap(c -> c.getDependencies().stream().filter(Dependency::isExtension).findFirst()) .map(Dependency::getId) .orElse(null) ); return usedAsStep || usedAsConnector; }); }
private String getLabel(Integration integration) { return String.format("Integration [%s]", Names.sanitize(integration.getName())); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/overviews") public ListResult<IntegrationOverview> getOverviews(@Context UriInfo uriInfo) { Stream<Integration> stream = getDataManager().fetchAll(Integration.class, new DeletedFilter(), new ReflectiveSorter<>(Integration.class, new SortOptionsFromQueryParams(uriInfo)), new PaginationFilter<>(new PaginationOptionsFromQueryParams(uriInfo)) ).getItems().stream(); return ListResult.of(stream.map(integration -> { String id = integration.getId().get(); List<IntegrationDeployment> deployments = getDataManager().fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id +":"), ReverseFilter.getInstance()) .getItems(); Optional<IntegrationBulletinBoard> bulletins = Optional .ofNullable(getDataManager().fetch(IntegrationBulletinBoard.class, id)); // find the deployment we want published.. return new IntegrationOverview(integration, bulletins, deployments.stream().findFirst()); }).collect(Collectors.toList())); }
private Collection<Dependency> collectDependencies(Integration integration) { List<Dependency> dependencies = new ArrayList<>(); for (Step step : integration.getSteps()) { step.getAction() .filter(WithDependencies.class::isInstance)