public Optional<String> getId() { return integration.getId(); }
@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 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(); }
/** * 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(); }
@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 ); }
/** * 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(); }
/** * 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(); }
@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(); }
@Override public void delete(String id) { Integration existing = Getter.super.get(id); //Set all integration status to Undeployed. Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", existing.getId().get()); if (deploymentIds != null && !deploymentIds.isEmpty()) { deploymentIds.stream() .map(i -> getDataManager().fetch(IntegrationDeployment.class, i)) .filter(r -> r != null) .map(r -> r.withTargetState(IntegrationDeploymentState.Unpublished)) .forEach(r -> getDataManager().update(r)); } Integration updatedIntegration = new Integration.Builder() .createFrom(existing) .updatedAt(System.currentTimeMillis()) .isDeleted(true) .build(); Updater.super.update(id, updatedIntegration); }
ids = new ArrayList<>(); for (Integration integration : dataManager.fetchAll(Integration.class).getItems()) { ids.add(integration.getId().get());
@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 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; } }