use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class Credentials method apply.
public Connection apply(final Connection updatedConnection, final CredentialFlowState flowState) {
final CredentialProvider credentialProvider = providerFrom(flowState);
final Connection withDerivedFlag = new Connection.Builder().createFrom(updatedConnection).isDerived(true).build();
final Connection appliedConnection = credentialProvider.applyTo(withDerivedFlag, flowState);
final Map<String, String> configuredProperties = appliedConnection.getConfiguredProperties();
final Map<String, ConfigurationProperty> properties = updatedConnection.getConnector().orElseGet(() -> dataManager.fetch(Connector.class, updatedConnection.getConnectorId())).getProperties();
final Map<String, String> encryptedConfiguredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, properties);
return new Connection.Builder().createFrom(appliedConnection).configuredProperties(encryptedConfiguredProperties).build();
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class IntegrationResourceManager method sanitize.
@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION")
@SuppressWarnings("PMD.ExcessiveMethodLength")
default Integration sanitize(Integration integration) {
// Always sanitize the integration name
String sanitizeIntegrationName = sanitize(integration.getName());
if (integration.getFlows().isEmpty()) {
return new Integration.Builder().createFrom(integration).name(sanitizeIntegrationName).build();
}
final List<Flow> replacementFlows = new ArrayList<>(integration.getFlows());
final ListIterator<Flow> flows = replacementFlows.listIterator();
while (flows.hasNext()) {
final Flow flow = flows.next();
if (flow.getSteps().isEmpty()) {
continue;
}
final List<Step> replacementSteps = new ArrayList<>(flow.getSteps());
final ListIterator<Step> steps = replacementSteps.listIterator();
while (steps.hasNext()) {
final Step source = steps.next();
Step replacement = source;
if (source.getConnection().isPresent()) {
final Connection connection = source.getConnection().get();
// If connector is not set, fetch it from data source and update connection
if (!connection.getConnector().isPresent()) {
Connector connector = loadConnector(connection.getConnectorId()).orElseThrow(() -> new IllegalArgumentException("Unable to fetch connector: " + connection.getConnectorId()));
// Add missing connector to connection.
Connection newConnection = new Connection.Builder().createFrom(connection).connector(connector).build();
// Replace with the new 'sanitized' step
replacement = new Step.Builder().createFrom(source).connection(newConnection).build();
}
// Prune Connector, nix actions. The action in use is on the Step
Connector prunedConnector = new Connector.Builder().createFrom(replacement.getConnection().get().getConnector().get()).actions(new ArrayList<>()).icon(null).build();
// Replace with the new 'pruned' connector
Connection prunedConnection = new Connection.Builder().createFrom(connection).connector(prunedConnector).icon(null).build();
// Replace with the new 'pruned' step
replacement = new Step.Builder().createFrom(source).connection(prunedConnection).build();
}
//
// If a template step then update it to ensure it
// has the correct dependencies
//
steps.set(TemplateStepLanguage.updateStep(replacement));
}
final Flow.Builder replacementFlowBuilder = flow.builder().createFrom(flow).steps(replacementSteps);
flows.set(replacementFlowBuilder.build());
// is fully implemented and schedule options are set on integration.
if (!flow.getScheduler().isPresent()) {
final Step firstStep = replacementSteps.get(0);
final Map<String, String> properties = new HashMap<>(firstStep.getConfiguredProperties());
String type = properties.remove("schedulerType");
final String expr = properties.remove("schedulerExpression");
if (StringUtils.isNotEmpty(expr)) {
if (StringUtils.isEmpty(type)) {
type = "timer";
}
final Scheduler scheduler = new Scheduler.Builder().type(Scheduler.Type.valueOf(type)).expression(expr).build();
final Flow replacementFlow = replacementFlowBuilder.scheduler(scheduler).build();
flows.set(replacementFlow);
}
// Replace first step so underlying connector won't fail uri param
// validation if schedule options were set.
steps.set(new Step.Builder().createFrom(firstStep).configuredProperties(properties).build());
}
}
return new Integration.Builder().createFrom(integration).name(sanitizeIntegrationName).flows(replacementFlows).build();
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGenerator method addPropertiesFrom.
private static void addPropertiesFrom(final Properties properties, final Integration integration, final IntegrationResourceManager resourceManager) {
final List<Flow> flows = integration.getFlows();
for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {
final Flow flow = flows.get(flowIndex);
final List<Step> steps = flow.getSteps();
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
final Step step = steps.get(stepIndex);
// Check if a step is of supported type.
if (StepKind.endpoint != step.getStepKind()) {
continue;
}
final Optional<Action> maybeAction = step.getAction();
final boolean isConnectorAction = maybeAction.map(a -> a instanceof ConnectorAction).orElse(Boolean.FALSE);
final boolean usesConnection = step.getConnection().isPresent();
// Check if a step has the required options
if (!isConnectorAction || !usesConnection) {
continue;
}
final Connection connection = step.getConnection().get();
final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
final ConnectorAction action = (ConnectorAction) maybeAction.get();
final ConnectorDescriptor actionDescriptor = action.getDescriptor();
final Optional<String> maybeComponentScheme = Optionals.first(actionDescriptor.getComponentScheme(), connector.getComponentScheme());
boolean hasComponentScheme = maybeComponentScheme.isPresent();
if (!hasComponentScheme) {
throw new UnsupportedOperationException("Old style of connectors from camel-connector are not supported anymore, please be sure that integration json satisfy connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()");
}
// Grab the component scheme from the component descriptor or
// from the connector
final String componentScheme = maybeComponentScheme.get();
final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
// https://github.com/syndesisio/syndesis/issues/1713
for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
final String propertyName = entry.getKey();
final ConfigurationProperty configurationProperty = entry.getValue();
final String defaultValue = Objects.toString(configurationProperty.getDefaultValue(), null);
boolean isSecret = connector.isSecret(propertyName) || action.isSecret(propertyName);
if (Strings.isEmptyOrBlank(defaultValue) && isSecret) {
addDecryptedKeyProperty(resourceManager, properties, flowIndex, stepIndex, componentScheme, propertyName, defaultValue);
}
}
addConfiguredPropertiesFrom(connector, action, connection, resourceManager, properties, flowIndex, stepIndex, componentScheme);
addConfiguredPropertiesFrom(connector, action, step, resourceManager, properties, flowIndex, stepIndex, componentScheme);
}
}
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGeneratorTest method testGenerateProject.
// ***************************
// Tests
// ***************************
@Test
public void testGenerateProject() throws Exception {
TestResourceManager resourceManager = new TestResourceManager();
Integration integration = resourceManager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(TestConstants.TIMER_CONNECTOR).build()).putConfiguredProperty("period", "5000").action(TestConstants.PERIODIC_TIMER_ACTION).build(), new Step.Builder().stepKind(StepKind.mapper).putConfiguredProperty("atlasmapping", "{}").build(), new Step.Builder().stepKind(StepKind.ruleFilter).putConfiguredProperty("predicate", "AND").putConfiguredProperty("rules", "[{ \"path\": \"in.header.counter\", \"op\": \">\", \"value\": \"10\" }]").build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-1").extensionId("my-extension-1").addDependency(Dependency.maven("org.slf4j:slf4j-api:1.7.11")).addDependency(Dependency.maven("org.slf4j:slf4j-simple:1.7.11")).addDependency(Dependency.maven("org.apache.camel:camel-spring-boot-starter:2.10.0")).build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-1-action-1").addTag("expose").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.ENDPOINT).entrypoint("direct:extension").build()).build()).build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-2").extensionId("my-extension-2").build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-1-action-1").addTag("expose").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.BEAN).entrypoint("com.example.MyExtension::action").build()).build()).build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-3").extensionId("my-extension-3").build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-2-action-1").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.STEP).entrypoint("com.example.MyStep").build()).build()).build(), new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("http-connection").connector(TestConstants.HTTP_CONNECTOR).build()).putConfiguredProperty("httpUri", "http://localhost:8080/hello").putConfiguredProperty("username", "admin").putConfiguredProperty("password", "admin").putConfiguredProperty("token", "mytoken").action(TestConstants.HTTP_GET_ACTION).build());
ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
configuration.getTemplates().setOverridePath(this.basePath);
configuration.getTemplates().getAdditionalResources().addAll(this.additionalResources);
configuration.setSecretMaskingEnabled(true);
Path runtimeDir = generate(integration, configuration, resourceManager);
assertFileContents(configuration, runtimeDir.resolve("pom.xml"), "pom.xml");
assertFileContentsJson(configuration, runtimeDir.resolve("src/main/resources/syndesis/integration/integration.json"), "integration.json");
assertFileContents(configuration, runtimeDir.resolve("src/main/resources/application.properties"), "application.properties");
assertFileContents(configuration, runtimeDir.resolve("src/main/resources/loader.properties"), "loader.properties");
assertFileContents(configuration, runtimeDir.resolve(".s2i/bin/assemble"), "assemble");
assertFileContents(configuration, runtimeDir.resolve("prometheus-config.yml"), "prometheus-config.yml");
assertThat(runtimeDir.resolve("extensions/my-extension-1.jar")).exists();
assertThat(runtimeDir.resolve("extensions/my-extension-2.jar")).exists();
assertThat(runtimeDir.resolve("extensions/my-extension-3.jar")).exists();
assertThat(runtimeDir.resolve("src/main/resources/mapping-flow-0-step-1.json")).exists();
// lets validate configuration when activity tracing is enabled.
try (Stream<Path> stream = Files.walk(testFolder.getRoot().toPath().resolve("integration-project"))) {
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
configuration.setActivityTracing(true);
runtimeDir = generate(integration, configuration, resourceManager);
assertFileContents(configuration, runtimeDir.resolve("src/main/resources/application.properties"), "application-tracing.properties");
assertThat(errors).isEmpty();
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ConnectionHandler method list.
@Override
public ListResult<ConnectionOverview> list(int page, int perPage) {
DataManager dataManager = getDataManager();
final ListResult<Connection> connectionResults = dataManager.fetchAll(Connection.class, new PaginationFilter<>(new PaginationOptionsFromQueryParams(page, perPage)));
final List<Connection> connections = connectionResults.getItems();
final List<ConnectionOverview> overviews = new ArrayList<>(connectionResults.getTotalCount());
for (Connection connection : connections) {
final String id = connection.getId().get();
final ConnectionOverview.Builder builder = new ConnectionOverview.Builder().createFrom(connection);
// set the connector
DataManagerSupport.fetch(dataManager, Connector.class, connection.getConnectorId()).ifPresent(builder::connector);
// set the board
DataManagerSupport.fetchBoard(dataManager, ConnectionBulletinBoard.class, id).ifPresent(builder::board);
overviews.add(builder.build());
}
return ListResult.of(overviews);
}
Aggregations