public String getName() { return integration.getName(); }
@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()); } } }
private String getLabel(Integration integration) { return String.format("Integration [%s]", Names.sanitize(integration.getName())); }
private String getLabel(Integration integration) { return String.format("Integration [%s]", Names.sanitize(integration.getName())); }
private String getLabel(IntegrationDeployment integrationDeployment) { return String.format("Integration [%s]", Names.sanitize(integrationDeployment.getSpec().getName())); }
@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); } }); }); }
@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 ); }
private boolean isBuildFailed(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildFailed(integrationDeployment.getSpec().getName()); }
private boolean isReady(IntegrationDeployment integrationDeployment) { return openShiftService().isDeploymentReady(integrationDeployment.getSpec().getName()); }
private boolean isBuildStarted(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildStarted(integrationDeployment.getSpec().getName()); }
public boolean isRunning(IntegrationDeployment integrationDeployment) { return openShiftService().isScaled(integrationDeployment.getSpec().getName(), 1); }
private ResourceIdentifier toIntegrationResourceIdentifier(IntegrationDeployment integrationDeployment) { return new ResourceIdentifier.Builder() .id(integrationDeployment.getIntegrationId()) .kind(Kind.Integration) .name(Optional.ofNullable(integrationDeployment.getSpec().getName())) .build(); }
private DeploymentData createDeploymentData(Integration integration, IntegrationDeployment integrationDeployment) { Properties applicationProperties = projectGenerator.generateApplicationProperties(integration); String username = integrationDeployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return DeploymentData.builder() .addLabel(OpenShiftService.INTEGRATION_ID_LABEL, Labels.sanitize(integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId")))) .addLabel(OpenShiftService.DEPLOYMENT_ID_LABEL, Integer.toString(integrationDeployment.getVersion())) .addLabel(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)) .addAnnotation(OpenShiftService.INTEGRATION_NAME_ANNOTATION, integration.getName()) .addAnnotation(OpenShiftService.INTEGRATION_ID_ANNOTATION, integrationDeployment.getIntegrationId().get()) .addAnnotation(OpenShiftService.DEPLOYMENT_VERSION_ANNOTATION, Integer.toString(integrationDeployment.getVersion())) .addSecretEntry("application.properties", propsToString(applicationProperties)) .build(); }
private void deploy(IntegrationDeployment integration, DeploymentData data) throws IOException { logInfo(integration, "Starting deployment"); openShiftService().deploy(integration.getSpec().getName(), data); logInfo(integration, "Deployment done"); }
@SuppressWarnings("PMD.DoNotUseThreads") private Runnable generateAddProjectTarEntries(Integration integration, OutputStream os) { return () -> { try ( TarArchiveOutputStream tos = new TarArchiveOutputStream(os)) { tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); addTarEntry(tos, "src/main/java/io/syndesis/example/Application.java", generate(integration, applicationJavaMustache)); addTarEntry(tos, "src/main/resources/application.properties", generate(integration, applicationPropertiesMustache)); addTarEntry(tos, "src/main/resources/syndesis.yml", generateFlow(tos, integration)); addTarEntry(tos, "pom.xml", generatePom(integration)); addResource(tos, ".s2i/bin/assemble", "s2i/assemble"); addExtensions(tos, integration); addAdditionalResources(tos); LOG.info("Integration [{}]: Project files written to output stream",Names.sanitize(integration.getName())); } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error(String.format("Exception while creating runtime build tar for integration %s : %s", integration.getName(), e.toString()), e); } } }; }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getSpec().getName()) || openShiftService().delete(integrationDeployment.getSpec().getName()) ? IntegrationDeploymentState.Unpublished : IntegrationDeploymentState.Pending; if (currentState == IntegrationDeploymentState.Unpublished) { logInfo(integrationDeployment,"Deleted"); IntegrationDeployment updated = new IntegrationDeployment.Builder().createFrom(integrationDeployment).addAllStepsDone(Collections.emptyList()).build(); dataManager.update(updated); } return new StateUpdate(currentState); }
private void build(IntegrationDeployment integration, DeploymentData data) throws IOException { InputStream tarInputStream = createProjectFiles(integration.getSpec()); logInfo(integration, "Created project files and starting build"); openShiftService().build(integration.getSpec().getName(), data, tarInputStream); }
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"); } }