Example usage for com.amazonaws.util StringUtils isNullOrEmpty

List of usage examples for com.amazonaws.util StringUtils isNullOrEmpty

Introduction

In this page you can find the example usage for com.amazonaws.util StringUtils isNullOrEmpty.

Prototype

public static boolean isNullOrEmpty(String value) 

Source Link

Usage

From source file:com.netflix.spinnaker.halyard.cli.command.v1.AbstractRemoteActionCommand.java

License:Apache License

@Override
protected void executeThis() {
    RemoteAction result = getRemoteAction().get();
    String scriptPath = result.getScriptPath();

    if (StringUtils.isNullOrEmpty(scriptPath)) {
        throw new RuntimeException("Expected a script to run, none provided.");
    }/*from  w w w. j a v  a2s .  c  o m*/

    boolean shouldRun;
    if (autoRun == null) {
        shouldRun = result.isAutoRun();
    } else {
        shouldRun = result.isAutoRun() && autoRun;
    }

    if (!shouldRun) {
        AnsiStoryBuilder storyBuilder = new AnsiStoryBuilder();

        AnsiParagraphBuilder paragraphBuilder = storyBuilder.addParagraph();
        paragraphBuilder.addSnippet(result.getScriptDescription());
        storyBuilder.addNewline();

        paragraphBuilder = storyBuilder.addParagraph();
        paragraphBuilder.addSnippet("Please run the following script:");
        storyBuilder.addNewline();

        paragraphBuilder = storyBuilder.addParagraph();
        paragraphBuilder.addSnippet(result.getScriptPath()).addStyle(AnsiStyle.UNDERLINE);

        AnsiUi.raw(storyBuilder.toString());
    } else {
        List<String> command = new ArrayList<>();
        command.add(scriptPath);
        JobRequest request = new JobRequest().setTokenizedCommand(command);
        JobExecutor executor = getJobExecutor();
        String jobId = executor.startJobFromStandardStreams(request);

        JobStatus status = executor.backoffWait(jobId, 100, TimeUnit.SECONDS.toMillis(2));

        if (status.getResult() != JobStatus.Result.SUCCESS) {
            AnsiUi.error("Error encountered running script. See above output for more details.");
            System.exit(1);
        }
    }
}

From source file:com.netflix.spinnaker.halyard.cli.command.v1.deploy.RunDeployCommand.java

License:Apache License

@Override
protected void executeThis() {
    RemoteAction result = new OperationHandler<RemoteAction>().setFailureMesssage("Failed to deploy Spinnaker.")
            .setOperation(Daemon.deployDeployment(getCurrentDeployment(), !noValidate, installOnly)).get();

    AnsiStoryBuilder storyBuilder = new AnsiStoryBuilder();
    AnsiParagraphBuilder paragraphBuilder = storyBuilder.addParagraph();
    String scriptDescription = result.getScriptDescription();
    String scriptPath = result.getScriptPath();
    if (!StringUtils.isNullOrEmpty(scriptPath)) {
        if (result.isAutoRun()) {
            paragraphBuilder.addSnippet(scriptDescription);

            List<String> command = new ArrayList<>();
            command.add(scriptPath);/* w  w w.  j  av a  2 s .c  o m*/
            JobRequest request = new JobRequest().setTokenizedCommand(command);
            JobExecutor executor = getJobExecutor();
            String jobId = executor.startJobFromStandardStreams(request);

            JobStatus status = executor.backoffWait(jobId, 10, TimeUnit.SECONDS.toMillis(5));

            if (status.getResult() != JobStatus.Result.SUCCESS) {
                AnsiUi.error("Failed to install Spinnaker. See above output for details.");
                System.exit(1);
            }
        } else {
            paragraphBuilder.addSnippet("Your deployment is almost complete.");
            storyBuilder.addNewline();
            paragraphBuilder = storyBuilder.addParagraph();
            paragraphBuilder.addSnippet(scriptDescription);
            storyBuilder.addNewline();
            paragraphBuilder = storyBuilder.addParagraph();
            paragraphBuilder.addSnippet("Please run the following command: ");
            storyBuilder.addNewline();
            paragraphBuilder = storyBuilder.addParagraph();
            paragraphBuilder.addSnippet(scriptPath).addStyle(AnsiStyle.UNDERLINE);
        }
    }

    AnsiUi.success("Deployment successful.\n");
}

From source file:com.netflix.spinnaker.halyard.deploy.services.v1.DeployService.java

License:Apache License

public RemoteAction installSpinnaker(String deploymentName) {
    DeploymentConfiguration deploymentConfiguration = deploymentService
            .getDeploymentConfiguration(deploymentName);
    Deployment deployment = deploymentFactory.create(deploymentConfiguration, null);
    RemoteAction result = deployment.install(spinnakerOutputPath);

    String script = result.getScript();
    if (!StringUtils.isNullOrEmpty(script)) {
        String resultPath = writeExecutable(script,
                halconfigDirectoryStructure.getInstallScriptPath(deploymentName));
        result.setScriptPath(resultPath);
    }/*  w  w w.  ja v  a 2  s  .  c  o m*/

    return result;
}

From source file:com.netflix.spinnaker.halyard.deploy.services.v1.DeployService.java

License:Apache License

public RemoteAction deploySpinnaker(String deploymentName) {
    DeploymentConfiguration deploymentConfiguration = deploymentService
            .getDeploymentConfiguration(deploymentName);
    GenerateResult generateResult = generateService.generateConfig(deploymentName);
    Path generateResultPath = halconfigDirectoryStructure.getGenerateResultPath(deploymentName);
    configParser.atomicWrite(generateResultPath, configParser.yamlToString(generateResult));
    halconfigParser.backupConfig(deploymentName);

    Deployment deployment = deploymentFactory.create(deploymentConfiguration, generateResult);

    FileSystem defaultFileSystem = FileSystems.getDefault();
    Path path = defaultFileSystem.getPath(spinnakerOutputPath, "spinnaker.yml");

    log.info("Writing spinnaker endpoints to " + path);

    configParser.atomicWrite(path, configParser.yamlToString(deployment.getEndpoints()));

    RemoteAction result = deployment.deploy(spinnakerOutputPath);

    String script = result.getScript();
    if (!StringUtils.isNullOrEmpty(script)) {
        String resultPath = writeExecutable(script,
                halconfigDirectoryStructure.getInstallScriptPath(deploymentName));
        result.setScriptPath(resultPath);
    }/*w  w w  . j a v a  2 s.  c  o m*/

    return result;
}

From source file:com.netflix.spinnaker.rosco.providers.oracle.OCIBakeHandler.java

License:Open Source License

@Override
public Map buildParameterMap(String region, Object virtualizationSettings, String imageName,
        BakeRequest bakeRequest, String appVersionStr) {
    OracleVirtualizationSettings oracleVirtualizationSettings = (OracleVirtualizationSettings) virtualizationSettings;

    ManagedOracleAccount managedAccount = resolveAccount(bakeRequest);

    Map<String, String> parameterMap = new HashMap<String, String>() {
        {//from   ww  w .j  av a2  s . com
            put("oracle_compartment_id", managedAccount.getCompartmentId());
            put("oracle_tenancy_id", managedAccount.getTenancyId());
            put("oracle_user_id", managedAccount.getUserId());
            put("oracle_fingerprint", managedAccount.getFingerprint());
            put("oracle_ssh_private_key_file_path", managedAccount.getSshPrivateKeyFilePath());
            put("oracle_pass_phrase", managedAccount.getPrivateKeyPassphrase());
            put("oracle_region", managedAccount.getRegion());
            put("oracle_availability_domain", oracleBakeryDefaults.getAvailabilityDomain());
            put("oracle_instance_shape", oracleBakeryDefaults.getInstanceShape());
            put("oracle_subnet_id", oracleBakeryDefaults.getSubnetId());
            put("oracle_base_image_id", oracleVirtualizationSettings.getBaseImageId());
            put("oracle_ssh_user_name", oracleVirtualizationSettings.getSshUserName());
            put("oracle_image_name", imageName);
        }
    };

    if (!StringUtils.isNullOrEmpty(bakeRequest.getBuild_info_url())) {
        parameterMap.put("build_info_url", bakeRequest.getBuild_info_url());
    }

    if (!StringUtils.isNullOrEmpty(appVersionStr)) {
        parameterMap.put("appversion", appVersionStr);
    }

    return parameterMap;
}

From source file:com.netflix.spinnaker.rosco.providers.oracle.OCIBakeHandler.java

License:Open Source License

private ManagedOracleAccount resolveAccount(BakeRequest bakeRequest) {
    ManagedOracleAccount managedAccount = null;

    if (StringUtils.isNullOrEmpty(bakeRequest.getAccount_name())) {
        if (oracleConfigurationProperties != null && oracleConfigurationProperties.getAccounts() != null
                && oracleConfigurationProperties.getAccounts().size() > 0) {
            managedAccount = oracleConfigurationProperties.getAccounts().get(0);
        }//  w  ww. j  a va  2s.co m
    } else {
        if (oracleConfigurationProperties != null && oracleConfigurationProperties.getAccounts() != null
                && oracleConfigurationProperties.getAccounts().size() > 0) {
            managedAccount = oracleConfigurationProperties.getAccounts().stream()
                    .filter(account -> bakeRequest.getAccount_name().equals(account.getName())).findAny()
                    .orElse(null);
        }
    }

    if (managedAccount == null) {
        throw new IllegalArgumentException(
                "Could not resolve Oracle account: (account_name=$bakeRequest.account_name).");
    }

    return managedAccount;
}

From source file:com.streamsets.pipeline.stage.destination.s3.DefaultFileHelper.java

License:Apache License

private String getUniqueDateWithIncrementalFileName(String keyPrefix) {
    fileCount++;//from  w ww. j a va2  s . co  m
    StringBuilder fileName = new StringBuilder();
    fileName = fileName.append(keyPrefix).append(fileCount);

    if (!StringUtils.isNullOrEmpty(s3TargetConfigBean.fileNameSuffix)) {
        fileName.append(DOT);
        fileName = fileName.append(s3TargetConfigBean.fileNameSuffix);
    }

    if (s3TargetConfigBean.compress) {
        fileName = fileName.append(GZIP_EXTENSION);
    }
    return fileName.toString();
}

From source file:io.helixservice.feature.configuration.dynamo.DynamoConfigResourceLocator.java

License:Open Source License

private void configureDynamoConnection() {
    if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) {
        //set the credentials as system properties
        System.setProperty("aws.accessKeyId", accessKey);
        System.setProperty("aws.secretKey", secretKey);
        LOG.info("accessKeyId and secretKey passed successfully via configuration");
    } else {/*from  www. j  av a  2  s . c om*/
        LOG.error("accessKeyId or secretKey not set");
    }

    client = new AmazonDynamoDBClient().withEndpoint(clientEndpoint);
    configTable = new DynamoDB(client).getTable(tableName);
}

From source file:io.macgyver.plugin.cloud.aws.AWSServiceFactory.java

License:Apache License

private AWSCredentialsProvider getCredentialsProvider(ServiceDefinition def) {

    String accessKey = def.getProperty("accessKey");
    String secretKey = def.getProperty("secretKey");

    if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) {
        logger.info("using static credentials " + accessKey + " for AWS service " + def.getName());
        return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
    }/*from   w w w.j  a v a 2  s  .com*/

    String sourceService = def.getProperty("sourceService");
    String assumeRoleName = def.getProperty("assumeRoleName");
    if (!StringUtils.isNullOrEmpty(sourceService) && !StringUtils.isNullOrEmpty(assumeRoleName)) {
        String roleArn = "arn:aws:iam::" + def.getProperty("accountId") + ":role/" + assumeRoleName;
        logger.info("using assume-role credentials for " + roleArn + " from " + sourceService
                + " for AWS service " + def.getName());
        return new AWSServiceClientAssumeRoleCredentialsProvider(registry, sourceService, roleArn);
    }

    logger.info("using default credentials provider for AWS service " + def.getName());
    return new DefaultAWSCredentialsProviderChain();

}

From source file:nz.net.orcon.kanban.controllers.BoardController.java

License:Open Source License

/**
 * Get History for Board based on Dates with Injected OCM
 *//* www  .  j  a va2  s.com*/
public Map<String, CardEvent> getHistory(ObjectContentManager ocm, String boardId, String category,
        String detail, String after, String before) throws Exception {

    QueryManager qm = ocm.getQueryManager();
    org.apache.jackrabbit.ocm.query.Filter qmFilter = qm.createFilter(CardEvent.class);
    qmFilter.setScope(String.format(URI.BOARD_URI, boardId + "//"));

    String categoryFilter = "";
    String detailFilter = "";

    if (category != null) {
        categoryFilter = "(@category='${category}')".replaceAll("\\$\\{category\\}", category);
    }

    if (detail != null) {
        detailFilter = "(jcr:contains(@detail,'${detail}'))".replaceAll("\\$\\{detail\\}", detail);
    }

    if (!StringUtils.isNullOrEmpty(categoryFilter) && !StringUtils.isNullOrEmpty(detailFilter)) {
        qmFilter.addJCRExpression(categoryFilter + " or " + detailFilter);
    } else if (!StringUtils.isNullOrEmpty(categoryFilter) && StringUtils.isNullOrEmpty(detailFilter)) {
        qmFilter.addJCRExpression(categoryFilter);
    } else if (StringUtils.isNullOrEmpty(categoryFilter) && !StringUtils.isNullOrEmpty(detailFilter)) {
        qmFilter.addJCRExpression(detailFilter);
    }

    if (after != null) {
        qmFilter.addJCRExpression("(@occuredTime>xs:dateTime('${after}'))".replaceAll("\\$\\{after\\}", after));
    }

    if (before != null) {
        qmFilter.addJCRExpression(
                "(@occuredTime<xs:dateTime('${before}'))".replaceAll("\\$\\{before\\}", before));
    }

    logger.info("Running Query: " + qmFilter.toString());

    Query query = qm.createQuery(qmFilter);
    Iterator<CardEvent> objectIterator = ocm.getObjectIterator(query);
    Map<String, CardEvent> list = new HashMap<String, CardEvent>();

    while (objectIterator.hasNext()) {
        CardEvent cardEvent = objectIterator.next();
        list.put(cardEvent.getCard(), cardEvent);
    }

    return list;
}