use of org.apache.atlas.setup.SetupException in project incubator-atlas by apache.
the class SetupStepsTest method shouldReleaseLockOnException.
@Test
public void shouldReleaseLockOnException() throws Exception {
Set<SetupStep> steps = new LinkedHashSet<>();
SetupStep setupStep1 = mock(SetupStep.class);
steps.add(setupStep1);
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
setupServerIdSelectionMocks();
setupSetupInProgressPathMocks(ZooDefs.Ids.OPEN_ACL_UNSAFE);
doThrow(new RuntimeException("Simulating setup failure.")).when(setupStep1).run();
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(lock);
InOrder inOrder = inOrder(lock, setupStep1);
SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
try {
setupSteps.runSetup();
} catch (Exception e) {
assertTrue(e instanceof SetupException);
}
inOrder.verify(lock).acquire();
inOrder.verify(setupStep1).run();
inOrder.verify(lock).release();
}
use of org.apache.atlas.setup.SetupException in project incubator-atlas by apache.
the class GraphSchemaInitializer method run.
@Override
public void run() throws SetupException {
LOG.info("Initializing graph schema backend.");
try {
// The implementation of this method internally creates the schema.
AtlasGraphProvider.getGraphInstance();
LOG.info("Completed initializing graph schema backend.");
} catch (Exception e) {
LOG.error("Could not initialize graph schema backend due to exception, {}", e.getMessage(), e);
throw new SetupException("Could not initialize graph schema due to exception", e);
}
}
use of org.apache.atlas.setup.SetupException in project incubator-atlas by apache.
the class SetupSteps method createSetupInProgressNode.
private void createSetupInProgressNode(Configuration configuration, HAConfiguration.ZookeeperProperties zookeeperProperties) throws SetupException {
String serverId = getServerId(configuration);
ACL acl = AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(), ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0));
List<ACL> acls = Arrays.asList(acl);
CuratorFramework client = curatorFactory.clientInstance();
try {
String path = lockPath(zookeeperProperties);
client.create().withACL(acls).forPath(path, serverId.getBytes(Charsets.UTF_8));
LOG.info("Created lock node {}", path);
} catch (Exception e) {
throw new SetupException("Could not create lock node before running setup.", e);
}
}
use of org.apache.atlas.setup.SetupException in project incubator-atlas by apache.
the class SetupSteps method runSetup.
/**
* Call each registered {@link SetupStep} one after the other.
* @throws SetupException Thrown with any error during running setup, including Zookeeper interactions, and
* individual failures in the {@link SetupStep}.
*/
@PostConstruct
public void runSetup() throws SetupException {
HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
InterProcessMutex lock = curatorFactory.lockInstance(zookeeperProperties.getZkRoot());
try {
LOG.info("Trying to acquire lock for running setup.");
lock.acquire();
LOG.info("Acquired lock for running setup.");
handleSetupInProgress(configuration, zookeeperProperties);
for (SetupStep step : setupSteps) {
LOG.info("Running setup step: {}", step);
step.run();
}
clearSetupInProgress(zookeeperProperties);
} catch (SetupException se) {
LOG.error("Got setup exception while trying to setup", se);
throw se;
} catch (Throwable e) {
LOG.error("Error running setup steps", e);
throw new SetupException("Error running setup steps", e);
} finally {
releaseLock(lock);
curatorFactory.close();
}
}
use of org.apache.atlas.setup.SetupException in project incubator-atlas by apache.
the class SetupSteps method clearSetupInProgress.
private void clearSetupInProgress(HAConfiguration.ZookeeperProperties zookeeperProperties) throws SetupException {
CuratorFramework client = curatorFactory.clientInstance();
String path = lockPath(zookeeperProperties);
try {
client.delete().forPath(path);
LOG.info("Deleted lock path after completing setup {}", path);
} catch (Exception e) {
throw new SetupException(String.format("SetupSteps.clearSetupInProgress: Failed to get Zookeeper node patH: %s", path), e);
}
}
Aggregations