private List<Step> getStepsInitialize() { return Flow.super.getSteps(); }
private Map<String, String> getMetadataInitialize() { return Flow.super.getMetadata(); }
EquivContext context = identifier(parentContext, another.getName(), another.getClass()); context.setFail(ONE_NULL, NULL, NOT_NULL); return false; EquivContext context = identifier(parentContext, one.getName(), one.getClass()); if (another == null) { context.setFail(ANOTHER_NULL, NOT_NULL, NULL); List<Step> mySteps = one.getSteps(); if (mySteps == null) { if (another.getSteps() != null) { context.setFail("steps", NULL, NOT_NULL); return false; Step anotherStep = another.findStepById(myStep.getId().get()).orElse(null); if (! equivalent(context, myStep, anotherStep)) { return false; pair(one.getId(), another.getId(), "id"), pair(one.getDescription(), another.getDescription(), "description"), pair(one.getTags(), another.getTags(), "tags"), pair(one.getName(), another.getName(), "name"));
@Test public void testSanitizeDefaultScheduler() { TestResourceManager resourceManager = new TestResourceManager(); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connector(TestConstants.HTTP_CONNECTOR) .build()) .putConfiguredProperty("schedulerExpression", "1s") .action(TestConstants.HTTP_GET_ACTION) .build() ); assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); final Flow sanitizedFlow = sanitized.getFlows().get(0); assertThat(sanitizedFlow.getScheduler().isPresent()).isTrue(); assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("type", Scheduler.Type.timer); assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("expression", "1s"); assertThat(sanitizedFlow.getSteps().get(0).getStepKind()).isEqualTo(StepKind.endpoint); assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-type"); assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-expression"); }
protected Flow flowWithExcerpts(Flow flow) { List<Step> steps = flow.getSteps(); if (steps == null || steps.isEmpty()) { return flow; } Step last = steps.get(steps.size() - 1); if (last.getConfiguredProperties().containsKey("httpResponseCode")) { String responseCode = last.getConfiguredProperties().get("httpResponseCode"); String responseDesc = decodeHttpReturnCode(steps, responseCode); return new Flow.Builder() .createFrom(flow) .putMetadata(EXCERPT_METADATA_KEY, responseDesc) .build(); } else if (flow.getMetadata(EXCERPT_METADATA_KEY).isPresent()) { Map<String, String> newMetadata = new HashMap<>(flow.getMetadata()); newMetadata.remove(EXCERPT_METADATA_KEY); return new Flow.Builder() .createFrom(flow) .metadata(newMetadata) .build(); } return flow; }
/** * If the integration has a scheduler, start the route with a timer or quartz2 * endpoint. */ private ProcessorDefinition<?> configureRouteScheduler(final Flow flow) throws URISyntaxException { if (flow.getScheduler().isPresent()) { Scheduler scheduler = flow.getScheduler().get(); // We now support simple timer only, cron support will be supported // later on. if (scheduler.isTimer()) { Map<String, String> properties = new HashMap<>(); properties.put("timerName", "integration"); properties.put("period", scheduler.getExpression()); final RuntimeCamelCatalog catalog = getContext().getRuntimeCamelCatalog(); final String uri = catalog.asEndpointUri("timer", properties, false); RouteDefinition route = this.from(uri); route.getInputs().get(0).setId("integration-scheduler"); flow.getId().ifPresent(route::setId); return route; } else { throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getType()); } } return null; }
Optional<Scheduler> schedulerOptional = instance.getScheduler(); if (schedulerOptional.isPresent()) { scheduler(schedulerOptional); Optional<String> descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); addAllConnections(instance.getConnections());
@Test public void testSanitizeScheduler() { TestResourceManager resourceManager = new TestResourceManager(); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connector(TestConstants.HTTP_CONNECTOR) .build()) .putConfiguredProperty("schedulerType", "timer") .putConfiguredProperty("schedulerExpression", "1s") .action(TestConstants.HTTP_GET_ACTION) .build() ); assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); final Flow sanitizedFlow = sanitized.getFlows().get(0); assertThat(sanitizedFlow.getScheduler().isPresent()).isTrue(); assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("type", Scheduler.Type.timer); assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("expression", "1s"); assertThat(sanitizedFlow.getSteps().get(0).getStepKind()).isEqualTo(StepKind.endpoint); assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-type"); assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-expression"); }
private static Predicate<Flow> idEndsWith(String end) { return f -> f.getId().map(id -> id.endsWith(end)).orElse(false); }
private static Stream<Step> allSteps(Integration integration) { return integration.getFlows().stream().flatMap(f -> f.getSteps().stream()); }
Flow anotherFlow = another.findFlowById(myFlow.getId().get()).orElse(null); if (! equivalent(context, myFlow, anotherFlow)) { return false;
/** * Collect dependencies. */ default Collection<Dependency> collectDependencies(Integration integration) { return collectDependencies(integration.getFlows().stream().flatMap(flow -> flow.getSteps().stream()).collect(Collectors.toList()), true); }
@JsonIgnore default Set<String> getUsedConnectorIds() { return Stream.concat( getFlows().stream() .flatMap(f -> f.getSteps().stream()) .map(Step::getConnection) .filter(Optional::isPresent) .map(Optional::get) .map(Connection::getConnectorId), getFlows().stream() .flatMap(f -> f.getSteps().stream()) .map(Step::getAction) .filter(Optional::isPresent) .map(Optional::get) .filter(ConnectorAction.class::isInstance) .map(ConnectorAction.class::cast) .map(ConnectorAction::getDescriptor) .filter(Objects::nonNull) .map(ConnectorDescriptor::getConnectorId) ) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
static boolean needsExposure(final IntegrationDeployment integrationDeployment) { return integrationDeployment.getSpec() .getFlows().stream().flatMap(f -> f.getSteps().stream()) .flatMap(step -> Optionals.asStream(step.getAction())) .flatMap(action -> action.getTags().stream()) .anyMatch("expose"::equals); } }
@Test public void testSanitizeConnectors() { TestResourceManager resourceManager = new TestResourceManager(); resourceManager.put(TestConstants.TIMER_CONNECTOR.getId().get(), TestConstants.TIMER_CONNECTOR); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connectorId(TestConstants.TIMER_CONNECTOR.getId().get()) .build()) .putConfiguredProperty("period", "5000") .action(TestConstants.PERIODIC_TIMER_ACTION) .build() ); final Optional<Connection> unsanitizedConnection = source.getFlows().get(0).getSteps().get(0).getConnection(); assertThat(unsanitizedConnection.isPresent()).isTrue(); assertThat(unsanitizedConnection.get().getConnector().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); final Optional<Connection> sanitizedConnection = sanitized.getFlows().get(0).getSteps().get(0).getConnection(); assertThat(sanitizedConnection.isPresent()).isTrue(); assertThat(sanitizedConnection.get().getConnector().isPresent()).isTrue(); assertThat(sanitizedConnection.get().getConnector().get()).isEqualTo(TestConstants.TIMER_CONNECTOR); }
.createFrom(sqlIntegration.getFlows().get(0).getSteps().get(0)) .connection(modSqlConnection) .build();