use of io.cdap.cdap.api.service.http.ServicePluginConfigurer in project cdap by caskdata.
the class RemoteConnectionSpecTask 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 pluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
ConnectorContext connectorContext = ConnectionUtils.getConnectorContext(pluginConfigurer);
SpecGenerationRequest specRequest = GSON.fromJson(request.getRequest(), SpecGenerationRequest.class);
try (Connector connector = getConnector(systemAppContext, pluginConfigurer, connection.getPlugin(), namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
ConnectorSpecRequest connectorSpecRequest = ConnectorSpecRequest.builder().setPath(specRequest.getPath()).setConnection(connection.getName()).setProperties(specRequest.getProperties()).build();
ConnectorSpec spec = connector.generateSpec(connectorContext, connectorSpecRequest);
ConnectorSpec newSpec = ConnectionUtils.filterSpecWithPluginNameAndType(spec, specRequest.getPluginName(), specRequest.getPluginType());
return GSON.toJson(ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), newSpec));
}
}
use of io.cdap.cdap.api.service.http.ServicePluginConfigurer in project cdap by caskdata.
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.api.service.http.ServicePluginConfigurer in project cdap by caskdata.
the class ConnectionHandler method sampleLocally.
private void sampleLocally(String namespace, String sampleRequestString, Connection conn, HttpServiceResponder responder) throws IOException {
SampleRequest sampleRequest = GSON.fromJson(sampleRequestString, SampleRequest.class);
ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), pluginConfigurer);
PluginInfo plugin = conn.getPlugin();
// 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(plugin.getArtifact()));
try (Connector connector = getConnector(pluginConfigurer, plugin, namespace, pluginSelector)) {
connector.configure(connectorConfigurer);
ConnectorSpecRequest specRequest = ConnectorSpecRequest.builder().setPath(sampleRequest.getPath()).setConnection(conn.getName()).setProperties(sampleRequest.getProperties()).build();
ConnectorSpec spec = connector.generateSpec(connectorContext, specRequest);
ConnectorDetail detail = ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), spec);
try {
SampleResponse sampleResponse = ConnectionUtils.getSampleResponse(connector, connectorContext, sampleRequest, detail, pluginConfigurer);
responder.sendString(GSON.toJson(sampleResponse));
} catch (ConnectionBadRequestException e) {
// should not happen
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, e.getMessage());
}
}
}
use of io.cdap.cdap.api.service.http.ServicePluginConfigurer in project cdap by caskdata.
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.api.service.http.ServicePluginConfigurer in project cdap by caskdata.
the class RemoteConnectionSampleTask 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 pluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
ConnectorContext connectorContext = ConnectionUtils.getConnectorContext(pluginConfigurer);
SampleRequest sampleRequest = GSON.fromJson(request.getRequest(), SampleRequest.class);
try (Connector connector = getConnector(systemAppContext, pluginConfigurer, connection.getPlugin(), namespace, pluginSelector)) {
connector.configure(new DefaultConnectorConfigurer(pluginConfigurer));
ConnectorSpecRequest specRequest = ConnectorSpecRequest.builder().setPath(sampleRequest.getPath()).setConnection(connection.getName()).setProperties(sampleRequest.getProperties()).build();
ConnectorSpec spec = connector.generateSpec(connectorContext, specRequest);
ConnectorDetail detail = ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), spec);
SampleResponse sampleResponse = ConnectionUtils.getSampleResponse(connector, connectorContext, sampleRequest, detail, pluginConfigurer);
return GSON.toJson(sampleResponse);
}
}
Aggregations