use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.
the class RemoteConnectionTestTask method execute.
@Override
public String execute(SystemAppTaskContext systemAppContext, RemoteConnectionRequest request) throws Exception {
String namespace = request.getNamespace();
ConnectionCreationRequest connectionCreationRequest = GSON.fromJson(request.getRequest(), ConnectionCreationRequest.class);
ServicePluginConfigurer pluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
SimpleFailureCollector failureCollector = new SimpleFailureCollector();
ConnectorContext connectorContext = new DefaultConnectorContext(failureCollector, pluginConfigurer);
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(connectionCreationRequest.getPlugin().getArtifact()));
try (Connector connector = getConnector(systemAppContext, pluginConfigurer, connectionCreationRequest.getPlugin(), namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
try {
connector.test(connectorContext);
failureCollector.getOrThrowException();
return "";
} catch (ValidationException e) {
return GSON.toJson(e.getFailures());
}
}
}
use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by caskdata.
the class ConnectionHandler method browseLocally.
private void browseLocally(String namespace, BrowseRequest browseRequest, Connection conn, HttpServiceResponder responder) throws IOException {
ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), pluginConfigurer);
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(conn.getPlugin().getArtifact()));
try (Connector connector = getConnector(pluginConfigurer, conn.getPlugin(), namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
responder.sendJson(connector.browse(connectorContext, browseRequest));
}
}
use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by caskdata.
the class RemoteConnectionBrowseTask method execute.
@Override
public String execute(SystemAppTaskContext systemAppContext, RemoteConnectionRequest request) throws Exception {
String namespace = request.getNamespace();
Connection connection = request.getConnection();
// Plugin selector and configurer
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(connection.getPlugin().getArtifact()));
ServicePluginConfigurer servicePluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
BrowseRequest browseRequest = GSON.fromJson(request.getRequest(), BrowseRequest.class);
try (Connector connector = getConnector(systemAppContext, servicePluginConfigurer, connection.getPlugin(), namespace, pluginSelector)) {
// configure and browse
connector.configure(new DefaultConnectorConfigurer(servicePluginConfigurer));
ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), servicePluginConfigurer);
BrowseDetail browseDetail = connector.browse(connectorContext, browseRequest);
return GSON.toJson(browseDetail);
}
}
use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.
the class ConnectionHandler method testLocally.
private void testLocally(String namespace, ConnectionCreationRequest creationRequest, HttpServiceResponder responder) throws IOException {
ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
SimpleFailureCollector failureCollector = new SimpleFailureCollector();
ConnectorContext connectorContext = new DefaultConnectorContext(failureCollector, pluginConfigurer);
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(creationRequest.getPlugin().getArtifact()));
try (Connector connector = getConnector(pluginConfigurer, creationRequest.getPlugin(), namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
try {
connector.test(connectorContext);
failureCollector.getOrThrowException();
} catch (ValidationException e) {
responder.sendJson(e.getFailures());
return;
}
}
responder.sendStatus(HttpURLConnection.HTTP_OK);
}
use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.
the class ConnectionHandler method specGenerationLocally.
private void specGenerationLocally(String namespace, SpecGenerationRequest specRequest, Connection conn, HttpServiceResponder responder) throws IOException {
ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), pluginConfigurer);
// use tracked selector to get exact plugin version that gets selected since the passed version can be null
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(conn.getPlugin().getArtifact()));
try (Connector connector = getConnector(pluginConfigurer, conn.getPlugin(), namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
ConnectorSpecRequest connectorSpecRequest = ConnectorSpecRequest.builder().setPath(specRequest.getPath()).setConnection(conn.getName()).setProperties(specRequest.getProperties()).build();
ConnectorSpec spec = connector.generateSpec(connectorContext, connectorSpecRequest);
ConnectorSpec newSpec = ConnectionUtils.filterSpecWithPluginNameAndType(spec, specRequest.getPluginName(), specRequest.getPluginType());
responder.sendString(GSON.toJson(ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), newSpec)));
}
}
Aggregations