use of io.cdap.cdap.api.NamespaceSummary in project cdap by cdapio.
the class DraftServiceTest method testGetDraftError.
@Test
public void testGetDraftError() throws IOException {
// Attempt to fetch an invalid draft from a valid namespace
NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
DraftId invalidId = new DraftId(namespace, "non-existent", "");
HttpResponse response = fetchDraft(invalidId);
DraftNotFoundException draftError = new DraftNotFoundException(invalidId);
Assert.assertEquals(404, response.getResponseCode());
Assert.assertEquals(draftError.getMessage(), response.getResponseBodyAsString());
// Attempt to fetch a valid draft but invalid namespace
DraftId draftId = new DraftId(namespace, "test-draft", "");
createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
NamespaceSummary invalidNamespace = new NamespaceSummary("non-existent", "", 0);
response = fetchDraft(new DraftId(invalidNamespace, "test-draft", ""));
Assert.assertEquals(500, response.getResponseCode());
// Sanity check, get the draft we just created
getDraft(draftId);
// Clean up
deleteDraftAndCheck(draftId);
}
use of io.cdap.cdap.api.NamespaceSummary in project cdap by cdapio.
the class DraftServiceTest method testDeleteDraftError.
@Test
public void testDeleteDraftError() throws IOException {
// Attempt to delete a draft that does not exist
NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
HttpResponse response = deleteDraft(new DraftId(namespace, "non-existent", ""));
Assert.assertEquals(404, response.getResponseCode());
}
use of io.cdap.cdap.api.NamespaceSummary in project cdap by cdapio.
the class ConnectionStoreTest method testBasicOperations.
@Test
public void testBasicOperations() throws Exception {
// put a connection in the store
NamespaceSummary namespace = new NamespaceSummary("default", "", 0L);
ConnectionId connectionId = new ConnectionId(namespace, "my_conn");
Connection expected = new Connection("my_conn", "GCS", "GCS connection", false, false, 0L, 0L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, expected, false);
// assert the connections
Assert.assertEquals(expected, connectionStore.getConnection(connectionId));
// update the connection, the connection should be updated
Connection updated = new Connection("my_conn", "GCS", "GCS connection updated", false, false, 1000L, 2000L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc", "serviceAccount", "secrect.json"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, updated, true);
Connection actual = connectionStore.getConnection(connectionId);
Assert.assertEquals(updated, actual);
// the creation time should remain the same
Assert.assertEquals(0L, actual.getCreatedTimeMillis());
// update time should get updated
Assert.assertEquals(2000L, actual.getUpdatedTimeMillis());
// add a new connection
ConnectionId newConnectioId = new ConnectionId(namespace, "mynewconn");
Connection newConnection = new Connection("mynewconn", "BigQuery", "BigQuery connection", false, false, 0L, 0L, new PluginInfo("BigQuery", "connector", "Google Cloud Platform", ImmutableMap.of("project", "myproject"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(newConnectioId, newConnection, false);
Assert.assertEquals(newConnection, connectionStore.getConnection(newConnectioId));
// list connections should have two connections
Assert.assertEquals(ImmutableList.of(updated, newConnection), connectionStore.listConnections(namespace));
// update first connection to a different name "my conn" which translates to same id "my_conn", with overwrite
// set to true, it should overwrite the connection and listing should still show two connections
connectionId = new ConnectionId(namespace, "my conn");
updated = new Connection("my conn", "GCS", "GCS connection updated", false, false, 1000L, 2000L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc", "serviceAccount", "secrect.json"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, updated, true);
actual = connectionStore.getConnection(connectionId);
Assert.assertEquals(updated, actual);
// list should still get 2 connections
Assert.assertEquals(ImmutableList.of(updated, newConnection), connectionStore.listConnections(namespace));
// delete the first one
connectionStore.deleteConnection(connectionId);
Assert.assertEquals(Collections.singletonList(newConnection), connectionStore.listConnections(namespace));
// delete the second one
connectionStore.deleteConnection(newConnectioId);
Assert.assertEquals(Collections.emptyList(), connectionStore.listConnections(namespace));
}
use of io.cdap.cdap.api.NamespaceSummary in project cdap by cdapio.
the class ConnectionStoreTest method testConflict.
@Test
public void testConflict() throws Exception {
// put a connection in the store
NamespaceSummary namespace = new NamespaceSummary("default", "", 0L);
ConnectionId connectionId = new ConnectionId(namespace, "my_conn");
Connection connection = new Connection("my_conn", "GCS", "GCS connection", false, false, 0L, 0L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, connection, false);
// use a different name but evaluate to same id, with overwrite to false, it should fail to update
try {
connectionId = new ConnectionId(namespace, "my conn");
connection = new Connection("my conn", "GCS", "GCS connection", false, false, 0L, 0L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, connection, false);
Assert.fail();
} catch (ConnectionConflictException e) {
// expected
}
// update the same name should also fail
try {
connectionId = new ConnectionId(namespace, "my_conn");
connection = new Connection("my conn", "GCS", "GCS connection", false, false, 0L, 0L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, connection, false);
Assert.fail();
} catch (ConnectionConflictException e) {
// expected
}
// check pre configured connection cannot get updated
connectionId = new ConnectionId(namespace, "default conn");
connection = new Connection("default conn", "GCS", "GCS connection", true, false, 0L, 0L, new PluginInfo("GCS", "connector", "Google Cloud Platform", ImmutableMap.of("project", "abc"), new ArtifactSelectorConfig("SYSTEM", "google-cloud", "1.0.0")));
connectionStore.saveConnection(connectionId, connection, false);
try {
connection = new Connection("default conn", "BigQuery", "", false, false, 0L, 0L, new PluginInfo("BigQuery", "connector", "", Collections.emptyMap(), new ArtifactSelectorConfig()));
connectionStore.saveConnection(connectionId, connection, true);
Assert.fail();
} catch (ConnectionConflictException e) {
// expected
}
// and pre-configured cannot be deleted
try {
connectionStore.deleteConnection(connectionId);
Assert.fail();
} catch (ConnectionConflictException e) {
// expected
}
}
use of io.cdap.cdap.api.NamespaceSummary in project cdap by cdapio.
the class StudioService method createPreconfiguredConnections.
private void createPreconfiguredConnections(SystemServiceContext context) throws IOException {
ConnectionStore connectionStore = new ConnectionStore(context);
for (PreconfiguredConnectionCreationRequest creationRequest : connectionConfig.getConnections()) {
if (creationRequest.getName() == null || creationRequest.getNamespace() == null) {
continue;
}
NamespaceSummary namespaceSummary = context.getAdmin().getNamespaceSummary(creationRequest.getNamespace());
if (namespaceSummary == null) {
LOG.warn("Namespace {} does not exist, skipping creating connection {}", creationRequest.getNamespace(), creationRequest.getName());
}
ConnectionId connectionId = new ConnectionId(namespaceSummary, creationRequest.getName());
long now = System.currentTimeMillis();
Connection connectionInfo = new Connection(creationRequest.getName(), connectionId.getConnectionId(), creationRequest.getPlugin().getName(), creationRequest.getDescription(), true, creationRequest.getName().equals(connectionConfig.getDefaultConnection()) ? true : false, now, now, creationRequest.getPlugin());
try {
connectionStore.saveConnection(connectionId, connectionInfo, false);
} catch (ConnectionConflictException e) {
// expected if the connection is already created
}
}
}
Aggregations