Search in sources :

Example 11 with NamespaceSummary

use of io.cdap.cdap.api.NamespaceSummary in project cdap by caskdata.

the class DraftServiceTest method testDraftAuthorization.

@Test
public void testDraftAuthorization() throws Exception {
    user = ALICE_NAME;
    HttpResponse response;
    // Check Alice can't list requests
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Grant her nesessary privilidges
    Authorizable namespaceAuthorizable = Authorizable.fromEntityId(NamespaceId.DEFAULT);
    getAccessController().grant(namespaceAuthorizable, ALICE_PRINCIPAL, EnumSet.of(StandardPermission.GET));
    // Check Alice can list requests now
    expectedCode = HttpURLConnection.HTTP_OK;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Check Bob still can't do it
    user = "bob";
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Check Alice can't do it for other namespace
    user = ALICE_NAME;
    listDrafts(TEST_NAMESPACE, false, "", "", "");
    // Check Alice can't create drafts
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    DraftId draftId = new DraftId(namespace, "draft1", ALICE_NAME);
    // She can't delete it as well
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    deleteDraft(draftId);
    createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    // Grant Alice create priviledge. Note that we don't differenciate create and update,
    // so update is used in both cases
    getAccessController().grant(namespaceAuthorizable, ALICE_PRINCIPAL, EnumSet.of(StandardPermission.UPDATE));
    // Now Alice should be able to create draft
    expectedCode = HttpURLConnection.HTTP_OK;
    createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    // Bob still can't get the draft
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    user = "bob";
    getDraft(draftId);
    // Alice should be able to delete draft
    expectedCode = HttpURLConnection.HTTP_OK;
    user = ALICE_NAME;
    deleteDraft(draftId);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) Authorizable(io.cdap.cdap.proto.security.Authorizable) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 12 with NamespaceSummary

use of io.cdap.cdap.api.NamespaceSummary in project cdap by caskdata.

the class DraftServiceTest method testCreateAndDeleteDraft.

private void testCreateAndDeleteDraft(DraftType draftType) throws IOException, TimeoutException, InterruptedException, ExecutionException {
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    DraftId draftId = new DraftId(namespace, "test-1", "admin");
    Draft expectedDraft;
    if (draftType == DraftType.Batch) {
        expectedDraft = createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    } else {
        expectedDraft = createStreamingPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    }
    Draft fetchedDraft = getDraft(draftId);
    Assert.assertTrue(sameDraft(fetchedDraft, expectedDraft));
    validateMetric(1, Constants.Metrics.DRAFT_COUNT);
    deleteDraftAndCheck(draftId);
    validateMetric(0, Constants.Metrics.DRAFT_COUNT);
}
Also used : Draft(io.cdap.cdap.datapipeline.draft.Draft) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId)

Example 13 with NamespaceSummary

use of io.cdap.cdap.api.NamespaceSummary in project cdap by caskdata.

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 14 with NamespaceSummary

use of io.cdap.cdap.api.NamespaceSummary in project cdap by caskdata.

the class ConnectionStoreTest method testNotFound.

@Test
public void testNotFound() throws Exception {
    ConnectionId connectionId = new ConnectionId(new NamespaceSummary("default", "", 0L), "nonexisting");
    // get non-existing connection
    try {
        connectionStore.getConnection(connectionId);
        Assert.fail();
    } catch (ConnectionNotFoundException e) {
    // expected
    }
    try {
        connectionStore.deleteConnection(connectionId);
        Assert.fail();
    } catch (ConnectionNotFoundException e) {
    // expected
    }
    // put a connection in the store
    NamespaceSummary oldNamespace = new NamespaceSummary("default", "", 0L);
    ConnectionId id = new ConnectionId(oldNamespace, "myconn");
    Connection connection = new Connection("myconn", "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(id, connection, false);
    // get the connection with a namespace with a higher generation id should fail
    try {
        connectionStore.getConnection(new ConnectionId(new NamespaceSummary("default", "", 1L), "myconn"));
        Assert.fail();
    } catch (ConnectionNotFoundException e) {
    // expected
    }
}
Also used : ConnectionId(io.cdap.cdap.etl.proto.connection.ConnectionId) ConnectionNotFoundException(io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException) 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 15 with NamespaceSummary

use of io.cdap.cdap.api.NamespaceSummary in project cdap by caskdata.

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