Search in sources :

Example 1 with SetupException

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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InOrder(org.mockito.InOrder) SetupException(org.apache.atlas.setup.SetupException) SetupStep(org.apache.atlas.setup.SetupStep) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex) SetupException(org.apache.atlas.setup.SetupException) Test(org.testng.annotations.Test)

Example 2 with SetupException

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);
    }
}
Also used : SetupException(org.apache.atlas.setup.SetupException) SetupException(org.apache.atlas.setup.SetupException)

Example 3 with SetupException

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) SetupException(org.apache.atlas.setup.SetupException) ACL(org.apache.zookeeper.data.ACL) SetupException(org.apache.atlas.setup.SetupException) AtlasException(org.apache.atlas.AtlasException)

Example 4 with SetupException

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();
    }
}
Also used : SetupException(org.apache.atlas.setup.SetupException) HAConfiguration(org.apache.atlas.ha.HAConfiguration) SetupStep(org.apache.atlas.setup.SetupStep) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex) PostConstruct(javax.annotation.PostConstruct)

Example 5 with SetupException

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) SetupException(org.apache.atlas.setup.SetupException) SetupException(org.apache.atlas.setup.SetupException) AtlasException(org.apache.atlas.AtlasException)

Aggregations

SetupException (org.apache.atlas.setup.SetupException)6 SetupStep (org.apache.atlas.setup.SetupStep)3 InterProcessMutex (org.apache.curator.framework.recipes.locks.InterProcessMutex)3 LinkedHashSet (java.util.LinkedHashSet)2 AtlasException (org.apache.atlas.AtlasException)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 Test (org.testng.annotations.Test)2 PostConstruct (javax.annotation.PostConstruct)1 HAConfiguration (org.apache.atlas.ha.HAConfiguration)1 ACL (org.apache.zookeeper.data.ACL)1 Stat (org.apache.zookeeper.data.Stat)1 InOrder (org.mockito.InOrder)1