Search in sources :

Example 1 with ConnectionNotFoundException

use of io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException in project cdap by caskdata.

the class ConnectionHandler method checkPutConnectionPermissions.

private void checkPutConnectionPermissions(ConnectionId connectionId) {
    boolean connectionExists;
    try {
        store.getConnection(connectionId);
        connectionExists = true;
    } catch (ConnectionNotFoundException e) {
        connectionExists = false;
    }
    if (connectionExists) {
        contextAccessEnforcer.enforce(new ConnectionEntityId(connectionId.getNamespace().getName(), connectionId.getConnectionId()), StandardPermission.UPDATE);
    } else {
        contextAccessEnforcer.enforce(new ConnectionEntityId(connectionId.getNamespace().getName(), connectionId.getConnectionId()), StandardPermission.CREATE);
    }
}
Also used : ConnectionNotFoundException(io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException) ConnectionEntityId(io.cdap.cdap.proto.id.ConnectionEntityId)

Example 2 with ConnectionNotFoundException

use of io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException 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)

Aggregations

ConnectionNotFoundException (io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException)2 NamespaceSummary (io.cdap.cdap.api.NamespaceSummary)1 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)1 Connection (io.cdap.cdap.etl.proto.connection.Connection)1 ConnectionId (io.cdap.cdap.etl.proto.connection.ConnectionId)1 PluginInfo (io.cdap.cdap.etl.proto.connection.PluginInfo)1 ConnectionEntityId (io.cdap.cdap.proto.id.ConnectionEntityId)1 Test (org.junit.Test)1