Search in sources :

Example 1 with EnvironmentDescription

use of com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElasticBeanstalkSetup method waitForEnvironmentReady.

/**
 * Wait for the Environment to be ready
 * @throws InterruptedException
 */
public void waitForEnvironmentReady(String environmentName) {
    EnvironmentDescription environment = null;
    do {
        environment = describeEnvironment(environmentName);
        if (environment == null)
            throw new IllegalArgumentException("Environment :" + environmentName + " does not exist");
        logger.info(String.format("Waiting for Environment '%1$s' to be ready.  Status: '%2$s'", environmentName, environment.getStatus()));
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    } while (!"Ready".equals(environment.getStatus()));
}
Also used : EnvironmentDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription)

Example 2 with EnvironmentDescription

use of com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElasticBeanstalkSetup method createAllEnvironments.

/**
 * Create the environments
 */
public void createAllEnvironments() {
    // setup the role, policy, and profile needed for rolling logs to S3.
    configureInstanceProfileForLogRolingToS3();
    // Create a profile that will used to enable logging.
    String plfmElbTemplateName = config.getElasticBeanstalkTemplateName() + "-plfm";
    String workerElbTemplateName = config.getElasticBeanstalkTemplateName() + "-worker";
    String portalElbTemplateName = config.getElasticBeanstalkTemplateName() + "-portal";
    // First create or update the templates using the current data.
    List<ConfigurationOptionSetting> cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.REPO);
    resources.setElasticBeanstalkConfigurationTemplate("plfm", createOrUpdateConfigurationTemplate(plfmElbTemplateName, cfgOptSettings));
    cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.WORKERS);
    resources.setElasticBeanstalkConfigurationTemplate("worker", createOrUpdateConfigurationTemplate(workerElbTemplateName, cfgOptSettings));
    cfgOptSettings = getAllElasticBeanstalkOptions(StackEnvironmentType.PORTAL);
    resources.setElasticBeanstalkConfigurationTemplate("portal", createOrUpdateConfigurationTemplate(portalElbTemplateName, cfgOptSettings));
    // Create the environments
    // portal
    createOrUpdateEnvironment(PREFIX_PORTAL, portalElbTemplateName, resources.getPortalApplicationVersion());
    // repo
    createOrUpdateEnvironment(PREFIX_REPO, plfmElbTemplateName, resources.getRepoApplicationVersion());
    // workers svc
    createOrUpdateEnvironment(PREFIX_WORKERS, workerElbTemplateName, resources.getWorkersApplicationVersion());
    // Fetch all of the results
    for (int numEnvironments = 0; numEnvironments < Constants.SVC_PREFIXES.size(); numEnvironments++) {
        try {
            Future<EnvironmentDescription> futureEnvDesc = completionSvc.take();
            EnvironmentDescription envDesc = futureEnvDesc.get();
            addCreatedEnvironmentDescriptionToResources(envDesc);
            logger.info("Environment created for : %s\n".format(envDesc.getApplicationName()));
        } catch (InterruptedException e) {
            // Exception in task
            logger.error("Error: InterruptedException");
            e.printStackTrace();
        } catch (ExecutionException e) {
            // Exception getting result
            logger.error("Error: ExecutionException");
            e.printStackTrace();
        }
    }
}
Also used : EnvironmentDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription) ExecutionException(java.util.concurrent.ExecutionException) ConfigurationOptionSetting(com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting)

Example 3 with EnvironmentDescription

use of com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElbAlarmSetupTest method setUp.

@Before
public void setUp() throws Exception {
    // Config
    config = TestHelper.createTestConfig("dev");
    // SNS topic
    resources = new GeneratedResources();
    resources.setStackInstanceNotificationTopicArn("topicArn");
    // Beanstalk environments
    EnvironmentDescription repoEnvDesc = new EnvironmentDescription().withEnvironmentName("repoEnvName");
    resources.setEnvironment(StackEnvironmentType.REPO, repoEnvDesc);
    EnvironmentDescription workersEnvDesc = new EnvironmentDescription().withEnvironmentName("workersEnvName");
    resources.setEnvironment(StackEnvironmentType.WORKERS, workersEnvDesc);
    EnvironmentDescription portalEnvDesc = new EnvironmentDescription().withEnvironmentName("portalEnvName");
    resources.setEnvironment(StackEnvironmentType.PORTAL, portalEnvDesc);
    // Clients
    beanstalkClient = mockFactory.createBeanstalkClient();
    mockCwClient = mockFactory.createCloudWatchClient();
    mockSleeper = Mockito.mock(Sleeper.class);
    setup = new ElbAlarmSetup(mockFactory, config, resources, mockSleeper);
}
Also used : EnvironmentDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription) Sleeper(org.sagebionetworks.stack.util.Sleeper) GeneratedResources(org.sagebionetworks.stack.GeneratedResources) Before(org.junit.Before)

Example 4 with EnvironmentDescription

use of com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElasticBeanstalkSetup method terminateEnvironment.

/**
 * Delete a single environment
 */
public void terminateEnvironment(String servicePrefix) {
    final String environmentName = config.getEnvironmentName(servicePrefix);
    final String environmentCName = config.getEnvironmentCNAMEPrefix(servicePrefix);
    EnvironmentDescription environment = describeEnvironment(environmentName);
    if (environment == null) {
        // Nothing to do except logger
        logger.debug(String.format("Environment name: '%1$s' does not exist!!!", environmentName, environmentCName));
    } else {
        // Delete environment
        logger.debug(String.format("Terminating environment name: '%1$s' with CNAME: '%2$s' ", environmentName, environmentCName));
        String environmentId = environment.getEnvironmentId();
        TerminateEnvironmentRequest ter = new TerminateEnvironmentRequest().withEnvironmentId(environmentId).withTerminateResources(Boolean.TRUE);
        TerminateEnvironmentResult terminateResult = beanstalkClient.terminateEnvironment(ter);
    }
}
Also used : TerminateEnvironmentRequest(com.amazonaws.services.elasticbeanstalk.model.TerminateEnvironmentRequest) TerminateEnvironmentResult(com.amazonaws.services.elasticbeanstalk.model.TerminateEnvironmentResult) EnvironmentDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription)

Example 5 with EnvironmentDescription

use of com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElasticBeanstalkSetup method createOrUpdateEnvironment.

/**
 * Create a single environment
 * @param version
 * @return
 */
public Future<EnvironmentDescription> createOrUpdateEnvironment(final String servicePrefix, final String cfgTemplateName, final ApplicationVersionDescription version) {
    final String environmentName = config.getEnvironmentName(servicePrefix);
    final String environmentCNAME = config.getEnvironmentCNAMEPrefix(servicePrefix);
    // This work is done on a separate thread.
    Callable<EnvironmentDescription> worker = new Callable<EnvironmentDescription>() {

        public EnvironmentDescription call() throws Exception {
            EnvironmentDescription environment = describeEnvironment(environmentName);
            if (environment == null) {
                // Create it since it does not exist
                logger.debug(String.format("Creating environment name: '%1$s' with CNAME: '%2$s' ", environmentName, environmentCNAME));
                CreateEnvironmentRequest cer = new CreateEnvironmentRequest(resources.getRepoApplicationVersion().getApplicationName(), environmentName);
                cer.setTemplateName(cfgTemplateName);
                cer.setVersionLabel(version.getVersionLabel());
                cer.setCNAMEPrefix(environmentCNAME);
                // Query for it again
                beanstalkClient.createEnvironment(cer);
                environment = describeEnvironment(environmentName);
                logger.debug(environment);
                return environment;
            } else {
                // Note: No support for upgrading the environment, should deploy new stack instead
                // Code deploys are OK
                logger.debug("Environment already exists: " + environmentName + " updating it...");
                // Should we update the version?
                if (!environment.getVersionLabel().equals(version.getVersionLabel())) {
                    logger.debug("Environment version need to be updated for: " + environmentName + "... updating it...");
                    // Now update the version.
                    updateEnvironmentVersionOnly(environmentName, version, environment);
                } else {
                // Force a template change
                // updateEnvironmentTemplateOnly(environmentName, version, environment);
                }
                // Return the new information.
                environment = describeEnvironment(environmentName);
                logger.debug(environment);
                return environment;
            }
        }
    };
    // Start the worker.
    return completionSvc.submit(worker);
}
Also used : CreateEnvironmentRequest(com.amazonaws.services.elasticbeanstalk.model.CreateEnvironmentRequest) EnvironmentDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription) Callable(java.util.concurrent.Callable)

Aggregations

EnvironmentDescription (com.amazonaws.services.elasticbeanstalk.model.EnvironmentDescription)5 ConfigurationOptionSetting (com.amazonaws.services.elasticbeanstalk.model.ConfigurationOptionSetting)1 CreateEnvironmentRequest (com.amazonaws.services.elasticbeanstalk.model.CreateEnvironmentRequest)1 TerminateEnvironmentRequest (com.amazonaws.services.elasticbeanstalk.model.TerminateEnvironmentRequest)1 TerminateEnvironmentResult (com.amazonaws.services.elasticbeanstalk.model.TerminateEnvironmentResult)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Before (org.junit.Before)1 GeneratedResources (org.sagebionetworks.stack.GeneratedResources)1 Sleeper (org.sagebionetworks.stack.util.Sleeper)1