Example usage for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getApplicationName

List of usage examples for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getApplicationName

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticbeanstalk.model EnvironmentDescription getApplicationName.

Prototype


public String getApplicationName() 

Source Link

Document

The name of the application associated with this environment.

Usage

From source file:br.com.ingenieux.mojo.beanstalk.cmd.dns.BindDomainsCommand.java

License:Apache License

protected boolean isSingleInstance(EnvironmentDescription env) {
    Validate.isTrue("WebServer".equals(env.getTier().getName()), "Not a Web Server environment!");

    final DescribeConfigurationSettingsResult describeConfigurationSettingsResult = parentMojo.getService()
            .describeConfigurationSettings(
                    new DescribeConfigurationSettingsRequest().withApplicationName(env.getApplicationName())
                            .withEnvironmentName(env.getEnvironmentName()));

    Validate.isTrue(1 == describeConfigurationSettingsResult.getConfigurationSettings().size(),
            "There should be one environment");

    final List<ConfigurationOptionSetting> optionSettings = describeConfigurationSettingsResult
            .getConfigurationSettings().get(0).getOptionSettings();

    for (ConfigurationOptionSetting optionSetting : optionSettings) {
        if (ConfigUtil.optionSettingMatchesP(optionSetting, "aws:elasticbeanstalk:environment",
                "EnvironmentType")) {
            return "SingleInstance".equals(optionSetting.getValue());
        }//from  w ww .java2  s. c  om
    }

    throw new IllegalStateException("Unreachable code!");
}

From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java

License:Apache License

public EnvironmentDescription executeInternal(WaitForEnvironmentContext context) throws Exception {
    // Those are invariants
    long timeoutMins = context.getTimeoutMins();

    Date expiresAt = new Date(System.currentTimeMillis() + MINS_TO_MSEC * timeoutMins);
    Date lastMessageRecord = new Date();

    info("Environment Lookup");

    List<Predicate<EnvironmentDescription>> envPredicates = getEnvironmentDescriptionPredicate(context);
    Predicate<EnvironmentDescription> corePredicate = envPredicates.get(0);
    Predicate<EnvironmentDescription> fullPredicate = Predicates.and(envPredicates);

    do {/*from www .j a  va 2  s.com*/
        DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest()
                .withApplicationName(context.getApplicationName()).withIncludeDeleted(true);

        final List<EnvironmentDescription> envs = parentMojo.getService().describeEnvironments(req)
                .getEnvironments();

        Collection<EnvironmentDescription> validEnvironments = Collections2.filter(envs, fullPredicate);

        debug("There are %d environments", validEnvironments.size());

        if (1 == validEnvironments.size()) {
            EnvironmentDescription foundEnvironment = validEnvironments.iterator().next();

            debug("Found environment %s", foundEnvironment);

            return foundEnvironment;
        } else {
            debug("Found %d environments. No good. Ignoring.", validEnvironments.size());

            for (EnvironmentDescription d : validEnvironments) {
                debug(" ... %s", d);
            }

            // ... but have we've got any closer match? If so, dump recent events

            Collection<EnvironmentDescription> foundEnvironments = Collections2.filter(envs, corePredicate);

            if (1 == foundEnvironments.size()) {
                EnvironmentDescription foundEnvironment = foundEnvironments.iterator().next();

                DescribeEventsResult events = service.describeEvents(
                        new DescribeEventsRequest().withApplicationName(foundEnvironment.getApplicationName())
                                .withStartTime(new Date(1000 + lastMessageRecord.getTime()))
                                .withEnvironmentId(foundEnvironment.getEnvironmentId()).withSeverity("TRACE"));

                Set<EventDescription> eventList = new TreeSet<EventDescription>(
                        new EventDescriptionComparator());

                eventList.addAll(events.getEvents());

                for (EventDescription d : eventList) {
                    info(String.format("%s %s %s", d.getSeverity(), d.getEventDate(), d.getMessage()));

                    if (d.getSeverity().equals(("ERROR"))) {
                        throw new MojoExecutionException(
                                "Something went wrong in while waiting for the environment setup to complete : "
                                        + d.getMessage());
                    }
                    lastMessageRecord = d.getEventDate();
                }
            }
        }

        sleepInterval(POLL_INTERVAL);
    } while (!timedOutP(expiresAt));

    throw new MojoExecutionException("Timed out");
}

From source file:jetbrains.buildServer.runner.elasticbeanstalk.AWSClient.java

License:Apache License

private void waitForDeployment(@NotNull String environmentId, String versionLabel, long startTime,
        int waitTimeoutSec, int waitIntervalSec) {
    myListener.deploymentWaitStarted(getEnvironment(environmentId).getEnvironmentName());

    EnvironmentDescription environment;
    String status;//  ww  w.  jav  a 2s  . c  om
    List<EventDescription> newEvents;
    List<EventDescription> errorEvents;
    boolean hasError;

    Date startDate = new Date(startTime);

    while (true) {
        environment = getEnvironment(environmentId);

        myListener.deploymentInProgress(environment.getEnvironmentName());

        status = getHumanReadableStatus(environment.getStatus());
        newEvents = getNewEvents(environmentId, startDate);

        for (EventDescription event : newEvents) {
            myListener.deploymentUpdate(event.getMessage());
        }

        if (System.currentTimeMillis() - startTime > waitTimeoutSec * 1000) {
            myListener.deploymentFailed(environment.getApplicationName(), environment.getEnvironmentName(),
                    versionLabel, true, null);
            return;
        }

        errorEvents = getErrorEvents(environmentId, versionLabel);
        hasError = errorEvents.size() > 0;
        if (!status.equals("updating") || hasError) {
            break;
        }

        try {
            Thread.sleep(waitIntervalSec * 1000);
        } catch (InterruptedException e) {
            processFailure(e);
            return;
        }
    }

    if (isSuccess(environment, versionLabel)) {
        myListener.deploymentSucceeded(versionLabel);
    } else {
        Listener.ErrorInfo errorEvent = hasError ? getErrorInfo(errorEvents.get(0)) : null;
        myListener.deploymentFailed(environment.getApplicationName(), environment.getEnvironmentName(),
                versionLabel, false, errorEvent);
    }
}