Search in sources :

Example 16 with NamespaceSummary

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);
}
Also used : DraftNotFoundException(io.cdap.cdap.datapipeline.draft.DraftNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 17 with NamespaceSummary

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());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 18 with NamespaceSummary

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));
}
Also used : ConnectionId(io.cdap.cdap.etl.proto.connection.ConnectionId) ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) Connection(io.cdap.cdap.etl.proto.connection.Connection) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) PluginInfo(io.cdap.cdap.etl.proto.connection.PluginInfo) Test(org.junit.Test)

Example 19 with NamespaceSummary

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
    }
}
Also used : ConnectionConflictException(io.cdap.cdap.etl.proto.connection.ConnectionConflictException) ConnectionId(io.cdap.cdap.etl.proto.connection.ConnectionId) ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) Connection(io.cdap.cdap.etl.proto.connection.Connection) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) PluginInfo(io.cdap.cdap.etl.proto.connection.PluginInfo) Test(org.junit.Test)

Example 20 with NamespaceSummary

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
        }
    }
}
Also used : ConnectionConflictException(io.cdap.cdap.etl.proto.connection.ConnectionConflictException) ConnectionId(io.cdap.cdap.etl.proto.connection.ConnectionId) Connection(io.cdap.cdap.etl.proto.connection.Connection) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) ConnectionStore(io.cdap.cdap.datapipeline.connection.ConnectionStore) PreconfiguredConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.PreconfiguredConnectionCreationRequest)

Aggregations

NamespaceSummary (io.cdap.cdap.api.NamespaceSummary)20 Test (org.junit.Test)14 DraftId (io.cdap.cdap.datapipeline.draft.DraftId)10 Connection (io.cdap.cdap.etl.proto.connection.Connection)8 ConnectionId (io.cdap.cdap.etl.proto.connection.ConnectionId)8 HttpResponse (io.cdap.common.http.HttpResponse)8 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)6 PluginInfo (io.cdap.cdap.etl.proto.connection.PluginInfo)6 Draft (io.cdap.cdap.datapipeline.draft.Draft)4 ConnectionConflictException (io.cdap.cdap.etl.proto.connection.ConnectionConflictException)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 FileSet (io.cdap.cdap.api.dataset.lib.FileSet)2 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)2 Get (io.cdap.cdap.api.dataset.table.Get)2 Put (io.cdap.cdap.api.dataset.table.Put)2 Table (io.cdap.cdap.api.dataset.table.Table)2 ConnectionStore (io.cdap.cdap.datapipeline.connection.ConnectionStore)2 DraftNotFoundException (io.cdap.cdap.datapipeline.draft.DraftNotFoundException)2 DraftStoreRequest (io.cdap.cdap.datapipeline.draft.DraftStoreRequest)2 ConnectionNotFoundException (io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException)2