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);
}
}
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
}
}
Aggregations