Search in sources :

Example 1 with AsterixInstance

use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.

the class AsterixInstallerIntegrationUtil method transformIntoRequiredState.

public static void transformIntoRequiredState(AsterixInstance.State state) throws Exception {
    AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(ASTERIX_INSTANCE_NAME);
    assert (instance != null);
    if (instance.getState().equals(state)) {
        return;
    }
    if (state.equals(AsterixInstance.State.UNUSABLE)) {
        throw new IllegalArgumentException("Invalid desired state");
    }
    String command = null;
    switch(instance.getState()) {
        case ACTIVE:
            command = "stop -n " + ASTERIX_INSTANCE_NAME;
            break;
        case INACTIVE:
            command = "start -n " + ASTERIX_INSTANCE_NAME;
            break;
        case UNUSABLE:
            command = "delete -n " + ASTERIX_INSTANCE_NAME;
            cmdHandler.processCommand(command.split(" "));
            throw new Exception("Cluster state was Unusable");
    }
    cmdHandler.processCommand(command.split(" "));
}
Also used : AsterixInstance(org.apache.asterix.event.model.AsterixInstance) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with AsterixInstance

use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.

the class RestoreConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((RestoreConfig) config).name;
    AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
    int backupId = ((RestoreConfig) config).backupId;
    List<BackupInfo> backupInfoList = instance.getBackupInfo();
    if (backupInfoList.size() <= backupId || backupId < 0) {
        throw new IllegalStateException("Invalid backup id");
    }
    BackupInfo backupInfo = backupInfoList.get(backupId);
    Patterns patterns = PatternCreator.INSTANCE.getRestoreAsterixPattern(instance, backupInfo);
    AsterixEventService.getAsterixEventServiceClient(instance.getCluster()).submit(patterns);
    LOGGER.info("Asterix instance: " + asterixInstanceName + " has been restored from backup");
}
Also used : BackupInfo(org.apache.asterix.event.model.BackupInfo) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns)

Example 3 with AsterixInstance

use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.

the class StartConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((StartConfig) config).name;
    AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
    AsterixEventServiceUtil.createAsterixZip(instance);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(instance.getCluster());
    Patterns asterixBinaryTransferPattern = PatternCreator.INSTANCE.getAsterixBinaryTransferPattern(asterixInstanceName, instance.getCluster());
    client.submit(asterixBinaryTransferPattern);
    // Start the watcher
    ClusterStateWatcher stateWatcher = ServiceProvider.INSTANCE.getLookupService().startWatchingClusterState(asterixInstanceName);
    AsterixEventServiceUtil.createClusterProperties(instance.getCluster(), instance.getAsterixConfiguration());
    Patterns patterns = PatternCreator.INSTANCE.getStartAsterixPattern(asterixInstanceName, instance.getCluster(), false);
    client.submit(patterns);
    // Check the cluster state
    ClusterState clusterState = stateWatcher.waitForClusterStart();
    if (clusterState != ClusterState.ACTIVE) {
        throw new Exception("CC failed to start");
    }
    AsterixEventServiceUtil.deleteDirectory(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.ASTERIX_DIR + File.separator + asterixInstanceName);
    AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
    VerificationUtil.updateInstanceWithRuntimeDescription(instance, runtimeState, true);
    LOGGER.info(instance.getDescription(false));
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
}
Also used : ClusterState(org.apache.asterix.common.api.IClusterManagementWork.ClusterState) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) ClusterStateWatcher(org.apache.asterix.event.service.ClusterStateWatcher) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState)

Example 4 with AsterixInstance

use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.

the class AsterixLifecycleIT method test_2_StartActiveInstance.

@Test
public void test_2_StartActiveInstance() throws Exception {
    try {
        LOGGER.info("Starting test: test_2_StartActiveInstance");
        AsterixInstallerIntegrationUtil.transformIntoRequiredState(State.INACTIVE);
        String command = "start -n " + AsterixInstallerIntegrationUtil.ASTERIX_INSTANCE_NAME;
        cmdHandler.processCommand(command.split(" "));
        AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(AsterixInstallerIntegrationUtil.ASTERIX_INSTANCE_NAME);
        AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
        assert (state.getFailedNCs().size() == 0 && state.isCcRunning());
        LOGGER.info("PASSED: test_2_StartActiveInstance");
    } catch (Exception e) {
        throw new Exception("Test configure installer " + "\" FAILED!", e);
    }
}
Also used : AsterixInstance(org.apache.asterix.event.model.AsterixInstance) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState) Test(org.junit.Test)

Example 5 with AsterixInstance

use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.

the class AsterixLifecycleIT method test_1_StopActiveInstance.

@Test
public void test_1_StopActiveInstance() throws Exception {
    try {
        LOGGER.info("Starting test: test_1_StopActiveInstance");
        AsterixInstallerIntegrationUtil.transformIntoRequiredState(State.ACTIVE);
        String command = "stop -n " + AsterixInstallerIntegrationUtil.ASTERIX_INSTANCE_NAME;
        cmdHandler.processCommand(command.split(" "));
        Thread.sleep(4000);
        AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(AsterixInstallerIntegrationUtil.ASTERIX_INSTANCE_NAME);
        AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
        assert (state.getFailedNCs().size() == NUM_NC && !state.isCcRunning());
        LOGGER.info("PASSED: test_1_StopActiveInstance");
    } catch (Exception e) {
        throw new Exception("Test configure installer " + "\" FAILED!", e);
    }
}
Also used : AsterixInstance(org.apache.asterix.event.model.AsterixInstance) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState) Test(org.junit.Test)

Aggregations

AsterixInstance (org.apache.asterix.event.model.AsterixInstance)25 Patterns (org.apache.asterix.event.schema.pattern.Patterns)12 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)8 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 Node (org.apache.asterix.event.schema.cluster.Node)5 Pattern (org.apache.asterix.event.schema.pattern.Pattern)4 InstallerException (org.apache.asterix.installer.error.InstallerException)4 PatternCreator (org.apache.asterix.event.util.PatternCreator)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 EventException (org.apache.asterix.event.error.EventException)2 BackupInfo (org.apache.asterix.event.model.BackupInfo)2 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)2 Cluster (org.apache.asterix.event.schema.cluster.Cluster)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2 ILookupService (org.apache.asterix.event.service.ILookupService)2