List of usage examples for com.amazonaws.regions Regions getName
public String getName()
From source file:com.brighttag.agathon.security.ec2.Ec2SecurityGroupModule.java
License:Apache License
@Provides @Singleton/*w w w. j av a2s. c o m*/ @Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY) Map<String, Region> provideRegions() { ImmutableMap.Builder<String, Region> regionMap = ImmutableMap.builder(); for (Regions region : Regions.values()) { // On first call, this makes a network request to fetch the metadata for all regions regionMap.put(region.getName(), Region.getRegion(region)); } return regionMap.build(); }
From source file:com.github.lpezet.antiope.metrics.aws.DefaultMetricsCollectorFactory.java
License:Open Source License
/** * Returns a instance of the Amazon CloudWatch request metric collector either by * starting up a new one or returning an existing one if it's already * started; null if any failure.// w ww.ja va2s.c o m */ @Override public ThreadedMetricsCollector getInstance() { Regions region = mConfig.getMetricsConfig().getRegion(); Integer oQSize = mConfig.getCloudWatchConfig().getMetricQueueSize(); Long oTimeoutMilli = mConfig.getCloudWatchConfig().getQueuePollTimeoutMilli(); CloudWatchConfig oCloudWatchConfig = new CloudWatchConfig(mConfig.getCloudWatchConfig()); if (mConfig.getCloudWatchConfig().getCredentialsProvider() != null) oCloudWatchConfig.setCredentialsProvider(mConfig.getCloudWatchConfig().getCredentialsProvider()); if (region != null) { String endPoint = "monitoring." + region.getName() + ".amazonaws.com"; oCloudWatchConfig.setCloudWatchEndPoint(endPoint); } if (oQSize != null) oCloudWatchConfig.setMetricQueueSize(oQSize.intValue()); if (oTimeoutMilli != null) oCloudWatchConfig.setQueuePollTimeoutMilli(oTimeoutMilli.longValue()); Config oConfig = new Config(); oConfig.setCloudWatchConfig(oCloudWatchConfig); oConfig.setMetricsConfig(mConfig.getMetricsConfig()); //MetricsCollectorSupport.startSingleton(oConfig); //return MetricsCollectorSupport.getInstance(); MetricsCollectorSupport oCollector = new MetricsCollectorSupport(oConfig); oCollector.start(); return oCollector; }
From source file:com.github.vatbub.awsvpnlauncher.RegionNotSupportedException.java
License:Apache License
public RegionNotSupportedException(Regions region) { this("Region " + region.getName() + " not supported for this operation."); }
From source file:com.netflix.genie.common.internal.configs.AwsAutoConfiguration.java
License:Apache License
/** * Get an AWS region provider instance. The rules for this basically follow what Spring Cloud AWS does but uses * the interface from the AWS SDK instead and provides a sensible default. * <p>//from w ww . ja v a 2 s . c om * See: <a href="https://tinyurl.com/y9edl6yr">Spring Cloud AWS Region Documentation</a> * * @param awsRegionProperties The cloud.aws.region.* properties * @return A region provider based on whether static was set by user, else auto, else default of us-east-1 */ @Bean @ConditionalOnMissingBean(AwsRegionProvider.class) public AwsRegionProvider awsRegionProvider(final AwsRegionProperties awsRegionProperties) { final String staticRegion = awsRegionProperties.getStatic(); if (StringUtils.isNotBlank(staticRegion)) { // Make sure we have a valid region. Will throw runtime exception if not. final Regions region = Regions.fromName(staticRegion); return new AwsRegionProvider() { /** * Always return the static configured region. * * {@inheritDoc} */ @Override public String getRegion() throws SdkClientException { return region.getName(); } }; } else if (awsRegionProperties.isAuto()) { return new DefaultAwsRegionProviderChain(); } else { // Sensible default return new AwsRegionProvider() { /** * Always default to us-east-1. * * {@inheritDoc} */ @Override public String getRegion() throws SdkClientException { return Regions.US_EAST_1.getName(); } }; } }
From source file:com.optimalbi.GUI.java
License:Apache License
private void loadSettings() { if (!settingsFile.exists()) { try {/*from ww w. j a v a2 s . c o m*/ if (!settingsFile.createNewFile()) { logger.error("Failed to create settings file"); return; } } catch (IOException e) { logger.error("Failed to create settings file " + e.getMessage()); } allRegions = new ArrayList<>(); currentRegions = new ArrayList<>(); Regions[] regionses = Regions.values(); for (Regions re : regionses) { if (!Region.getRegion(re).getName().equals(Regions.GovCloud.getName()) & !Region.getRegion(re).getName().equals(Regions.CN_NORTH_1.getName())) { AmazonRegion tempRegion; if (re.getName().equals(Regions.AP_SOUTHEAST_2.getName())) { tempRegion = new AmazonRegion(Region.getRegion(re), true); currentRegions.add(Region.getRegion(re)); } else { tempRegion = new AmazonRegion(Region.getRegion(re), false); } allRegions.add(tempRegion); } } saveSettings(); } BufferedReader fileReader = null; allRegions = new ArrayList<>(); currentRegions = new ArrayList<>(); List<String> activeRegions = new ArrayList<>(); try { fileReader = new BufferedReader(new FileReader(settingsFile)); String line = fileReader.readLine(); while (line != null) { String[] split = line.split(" "); if (split.length > 1) { switch (split[0].toLowerCase()) { case "regions": String[] argument = split[1].split(","); if (argument.length > 0) { Collections.addAll(activeRegions, argument); } break; case "password": encryptedPassword = split[1]; break; default: logger.warn("Unknown setting " + split[0]); break; } } else { if (!split[0].equals("")) logger.warn("No data entered for " + split[0]); } line = fileReader.readLine(); } } catch (IOException e) { logger.error("Failed to read settings file: " + e.getMessage()); setLabelCentre("Failed to read settings file: " + e.getMessage()); } Regions[] regionses = Regions.values(); for (Regions re : regionses) { if (!Region.getRegion(re).getName().equals(Regions.GovCloud.getName()) & !Region.getRegion(re).getName().equals(Regions.CN_NORTH_1.getName())) { AmazonRegion tempRegion; if (activeRegions.contains(re.getName())) { tempRegion = new AmazonRegion(Region.getRegion(re), true); currentRegions.add(Region.getRegion(re)); } else { tempRegion = new AmazonRegion(Region.getRegion(re), false); } allRegions.add(tempRegion); } } }
From source file:com.remediatetheflag.global.persistence.HibernatePersistenceFacade.java
License:Apache License
public RTFECSTaskDefinition getTaskDefinitionFromUUID(String uuid, Regions region) { HibernateSessionTransactionWrapper hb = openSessionTransaction(); try {/*from w w w . j a v a2s . com*/ RTFECSTaskDefinitionForExerciseInRegion td = (RTFECSTaskDefinitionForExerciseInRegion) hb.localSession .createQuery("select t from ECSTaskDefinitionForExerciseInRegion t join t.exercise ex where " + " t.region = :regId and ex.uuid = :uuid and t.active is true") .setParameter("regId", region).setParameter("uuid", uuid).setMaxResults(1).setFirstResult(0) .getSingleResult(); closeSessionTransaction(hb); return td.getTaskDefinition(); } catch (Exception e) { closeSessionTransaction(hb); logger.warn("Exercise uuid " + uuid + " does not have task definition in region " + region.getName() + " : " + e.getMessage()); return null; } }
From source file:com.remediatetheflag.global.persistence.HibernatePersistenceFacade.java
License:Apache License
public RTFECSTaskDefinition getTaskDefinitionForExerciseInRegion(Integer exerciseId, Regions region) { HibernateSessionTransactionWrapper hb = openSessionTransaction(); try {// ww w .j a v a 2 s . c om RTFECSTaskDefinitionForExerciseInRegion td = (RTFECSTaskDefinitionForExerciseInRegion) hb.localSession .createQuery("from ECSTaskDefinitionForExerciseInRegion where " + " region = :regId and exerciseId = :exId and active is true") .setParameter("regId", region).setParameter("exId", exerciseId).setMaxResults(1) .setFirstResult(0).getSingleResult(); closeSessionTransaction(hb); return td.getTaskDefinition(); } catch (Exception e) { closeSessionTransaction(hb); logger.warn("Exercise id " + exerciseId + " does not have task definition in region " + region.getName() + " : " + e.getMessage()); return null; } }
From source file:jp.classmethod.aws.RegionFactoryBean.java
License:Apache License
@Override public Region getObject() { Regions region = defaultRegion;/*from w ww. ja v a 2 s . co m*/ for (Regions r : Regions.values()) { if (r.getName().equals(metadata.getRegion())) { region = r; break; } } Region bean = Region.getRegion(region); logger.info("loaded {}", bean); return bean; }
From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java
License:Apache License
public static List<String> getAvailableRegions() { List<String> availableRegions = new ArrayList<String>(Regions.values().length); for (Regions region : Regions.values()) availableRegions.add(region.getName()); return availableRegions; }
From source file:org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer.java
License:Apache License
/** * Checks that the values specified for config keys in the properties config is recognizable. *//*from www .ja v a2 s. c o m*/ protected static void validatePropertiesConfig(Properties config) { if (!config.containsKey(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_TYPE)) { // if the credential provider type is not specified, it will default to BASIC later on, // so the Access Key ID and Secret Key must be given if (!config.containsKey(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_ACCESSKEYID) || !config .containsKey(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_SECRETKEY)) { throw new IllegalArgumentException("Please set values for AWS Access Key ID ('" + KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_ACCESSKEYID + "') " + "and Secret Key ('" + KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_SECRETKEY + "') when using the BASIC AWS credential provider type."); } } else { String credentialsProviderType = config .getProperty(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_TYPE); // value specified for KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_TYPE needs to be recognizable CredentialProviderType providerType; try { providerType = CredentialProviderType.valueOf(credentialsProviderType); } catch (IllegalArgumentException e) { StringBuilder sb = new StringBuilder(); for (CredentialProviderType type : CredentialProviderType.values()) { sb.append(type.toString()).append(", "); } throw new IllegalArgumentException( "Invalid AWS Credential Provider Type set in config. Valid values are: " + sb.toString()); } // if BASIC type is used, also check that the Access Key ID and Secret Key is supplied if (providerType == CredentialProviderType.BASIC) { if (!config.containsKey(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_ACCESSKEYID) || !config.containsKey( KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_SECRETKEY)) { throw new IllegalArgumentException("Please set values for AWS Access Key ID ('" + KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_ACCESSKEYID + "') " + "and Secret Key ('" + KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_SECRETKEY + "') when using the BASIC AWS credential provider type."); } } } if (!config.containsKey(KinesisConfigConstants.CONFIG_AWS_REGION)) { throw new IllegalArgumentException("The AWS region ('" + KinesisConfigConstants.CONFIG_AWS_REGION + "') must be set in the config."); } else { // specified AWS Region name must be recognizable if (!AWSUtil.isValidRegion(config.getProperty(KinesisConfigConstants.CONFIG_AWS_REGION))) { StringBuilder sb = new StringBuilder(); for (Regions region : Regions.values()) { sb.append(region.getName()).append(", "); } throw new IllegalArgumentException( "Invalid AWS region set in config. Valid values are: " + sb.toString()); } } if (config.containsKey(KinesisConfigConstants.CONFIG_STREAM_INIT_POSITION_TYPE)) { String initPosType = config.getProperty(KinesisConfigConstants.CONFIG_STREAM_INIT_POSITION_TYPE); // specified initial position in stream must be either LATEST or TRIM_HORIZON try { InitialPosition.valueOf(initPosType); } catch (IllegalArgumentException e) { StringBuilder sb = new StringBuilder(); for (InitialPosition pos : InitialPosition.values()) { sb.append(pos.toString()).append(", "); } throw new IllegalArgumentException( "Invalid initial position in stream set in config. Valid values are: " + sb.toString()); } } if (config.containsKey(KinesisConfigConstants.CONFIG_STREAM_DESCRIBE_RETRIES)) { try { Integer.parseInt(config.getProperty(KinesisConfigConstants.CONFIG_STREAM_DESCRIBE_RETRIES)); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Invalid value given for describeStream stream operation retry count. Must be a valid integer value."); } } if (config.containsKey(KinesisConfigConstants.CONFIG_STREAM_DESCRIBE_BACKOFF)) { try { Long.parseLong(config.getProperty(KinesisConfigConstants.CONFIG_STREAM_DESCRIBE_BACKOFF)); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Invalid value given for describeStream stream operation backoff milliseconds. Must be a valid long value."); } } if (config.containsKey(KinesisConfigConstants.CONFIG_SHARD_RECORDS_PER_GET)) { try { Integer.parseInt(config.getProperty(KinesisConfigConstants.CONFIG_SHARD_RECORDS_PER_GET)); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Invalid value given for maximum records per getRecords shard operation. Must be a valid integer value."); } } }