List of usage examples for com.amazonaws.regions Region getName
public String getName()
From source file:com.nextdoor.bender.utils.Passwords.java
License:Apache License
public static String decrypt(String str, Region region) throws UnsupportedEncodingException { if (isJUnitTest()) { return str; }/*from w ww . j a va 2s .c om*/ AWSKMS kms = AWSKMSClientBuilder.standard().withRegion(region.getName()).build(); /* * The KMS ciphertext is base64 encoded and must be decoded before the request is made */ String cipherString = str; byte[] cipherBytes = Base64.decode(cipherString); /* * Create decode request and decode */ ByteBuffer cipherBuffer = ByteBuffer.wrap(cipherBytes); DecryptRequest req = new DecryptRequest().withCiphertextBlob(cipherBuffer); DecryptResult resp = kms.decrypt(req); /* * Convert the response plaintext bytes to a string */ return new String(resp.getPlaintext().array(), Charset.forName("UTF-8")); }
From source file:com.optimalbi.AmazonAccount.java
License:Apache License
private void populateEc2() throws AmazonClientException { for (Region region : getRegions()) { try {/* w w w .j a v a 2 s . c o m*/ // services.addAll(Ec2Service.populateServices(region, getCredentials(), getLogger(), pricing)); AmazonEC2Client ec2 = new AmazonEC2Client(getCredentials().getCredentials()); ec2.setRegion(region); DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> inst = new HashSet<>(); for (Reservation reservation : reservations) { inst.addAll(reservation.getInstances()); } getLogger().info("EC2, Adding " + inst.size() + " instances from " + region.getName()); for (Instance i : inst) { Service temp = new LocalEc2Service(i.getInstanceId(), getCredentials(), region, ec2, getLogger()); if (servicePricings != null && servicePricings.size() > 0) { temp.attachPricing(servicePricings.get(region).getEc2Pricing()); } services.add(temp); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.AmazonAccount.java
License:Apache License
private void populateRedshift() throws AmazonClientException { for (Region region : getRegions()) { try {/*from w w w.j a va2 s.c om*/ if (region.isServiceSupported(ServiceAbbreviations.RedShift)) { // services.addAll(RedshiftService.populateServices(region, getCredentials(), getLogger())); AmazonRedshiftClient redshift = new AmazonRedshiftClient(getCredentials().getCredentials()); redshift.setRegion(region); DescribeClustersResult clusterResult; List<Cluster> clusters; try { clusterResult = redshift.describeClusters(); clusters = clusterResult.getClusters(); } catch (Exception e) { throw new AmazonClientException("Failed to get clusters " + e.getMessage()); } getLogger().info("Redshift, Adding " + clusters.size() + " clusters from " + region.getName()); for (Cluster cluster : clusters) { getLogger().info("Cluster: " + cluster.getClusterIdentifier()); LocalRedshiftService temp = new LocalRedshiftService(cluster.getDBName(), getCredentials(), region, cluster, getLogger()); if (servicePricings != null && servicePricings.size() > 0) { temp.attachPricing(servicePricings.get(region).getRedshiftPricing()); } services.add(temp); } } else { getLogger().info("Redshift, NOPE from " + region.getName()); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.AmazonAccount.java
License:Apache License
private void populateRDS() throws AmazonClientException { for (Region region : getRegions()) { try {/* www .j a v a 2 s .c o m*/ if (region.isServiceSupported(ServiceAbbreviations.RDS)) { AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials()); rds.setRegion(region); DescribeDBInstancesResult result = rds.describeDBInstances(); List<DBInstance> instances = result.getDBInstances(); getLogger().info("RDS, Adding " + instances.size() + " instances from " + region.getName()); for (DBInstance i : instances) { LocalRDSService temp; if (i.getDBName() != null) { temp = new LocalRDSService(i.getDBName(), getCredentials(), region, i, getLogger()); } else { temp = new LocalRDSService(i.getDBInstanceIdentifier(), getCredentials(), region, i, getLogger()); } if (servicePricings != null && servicePricings.size() > 0) { if (servicePricings.get(region).getRDSPricing() != null) { temp.attachPricing(servicePricings.get(region).getRDSPricing()); } } services.add(temp); } } else { getLogger().info("RDS, NOPE from " + region.getName()); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.Controller.AmazonAccount.java
License:Apache License
private void populateEc2() throws AmazonClientException { Map<String, Double> pricing = readEc2Pricing(); for (Region region : getRegions()) { try {/*w w w .j a v a2s . c o m*/ // services.addAll(Ec2Service.populateServices(region, getCredentials(), getLogger(), pricing)); AmazonEC2Client ec2 = new AmazonEC2Client(getCredentials().getCredentials()); ec2.setRegion(region); DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> inst = new HashSet<>(); for (Reservation reservation : reservations) { inst.addAll(reservation.getInstances()); } getLogger().info("EC2, Adding " + inst.size() + " instances from " + region.getName()); for (Instance i : inst) { Service temp = new LocalEc2Service(i.getInstanceId(), getCredentials(), region, ec2, getLogger()); if (pricing != null) { temp.attachPricing(pricing); } services.add(temp); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.Controller.AmazonAccount.java
License:Apache License
private void populateRedshift() throws AmazonClientException { for (Region region : getRegions()) { try {// ww w. ja va 2s . c om if (region.isServiceSupported(ServiceAbbreviations.RedShift)) { // services.addAll(RedshiftService.populateServices(region, getCredentials(), getLogger())); AmazonRedshiftClient redshift = new AmazonRedshiftClient(getCredentials().getCredentials()); redshift.setRegion(region); DescribeClustersResult clusterResult; List<Cluster> clusters; try { clusterResult = redshift.describeClusters(); clusters = clusterResult.getClusters(); } catch (Exception e) { throw new AmazonClientException("Failed to get clusters " + e.getMessage()); } getLogger().info("Redshift, Adding " + clusters.size() + " clusters from " + region.getName()); for (Cluster cluster : clusters) { getLogger().info("Cluster: " + cluster.getClusterIdentifier()); services.add(new LocalRedshiftService(cluster.getClusterIdentifier(), getCredentials(), region, cluster, getLogger())); } } else { getLogger().info("Redshift, NOPE from " + region.getName()); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.Controller.AmazonAccount.java
License:Apache License
private void populateRDS() throws AmazonClientException { for (Region region : getRegions()) { try {// w ww. j a v a2s . c o m if (region.isServiceSupported(ServiceAbbreviations.RDS)) { // services.addAll(RDSService.populateServices(region, getCredentials(), getLogger())); AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials()); rds.setRegion(region); DescribeDBInstancesResult result = rds.describeDBInstances(); List<DBInstance> instances = result.getDBInstances(); getLogger().info("RDS, Adding " + instances.size() + " instances from " + region.getName()); services.addAll( instances .stream().map(i -> new LocalRDSService(i.getDBInstanceIdentifier(), getCredentials(), region, i, getLogger())) .collect(Collectors.toList())); } else { getLogger().info("RDS, NOPE from " + region.getName()); } } catch (AmazonClientException e) { throw new AmazonClientException(region.getName() + " " + e.getMessage()); } completed.set(completed.get() + 1); } }
From source file:com.optimalbi.GUI.java
License:Apache License
private ToolBar updateToolbar() { Map<String, String> regionNames = Service.regionNames(); List<Button> toolButtons = new ArrayList<>(); Button summary = guiFactory.createButton("Summary", -1, -1); summary.setOnAction(ActionEvent -> { viewedRegion = "summary"; updatePainting();/*from w w w . j a va2 s . c o m*/ }); toolButtons.add(summary); Button all = guiFactory.createButton("All", -1, -1); all.setOnAction(ActionEvent -> { viewedRegion = "all"; updatePainting(); }); toolButtons.add(all); for (Region region : currentRegions) { Button adding; if (regionNames.containsKey(region.getName())) { adding = guiFactory.createButton(regionNames.get(region.getName()), -1, -1); } else { adding = guiFactory.createButton(region.getName(), -1, -1); } adding.setOnAction(ActionEvent -> { viewedRegion = region.getName(); updatePainting(); }); toolButtons.add(adding); } ToolBar toolBar = new ToolBar(); toolBar.getItems().addAll(toolButtons); toolBar.getStylesheets().add(styleSheet); toolBar.getStyleClass().add("toolbar"); toolBar.setPrefWidth(primaryScreenBounds.getWidth()); //If you click on the top and their is a dialog to show, display the dialog toolBar.setOnMouseClicked(event -> { if (dialog != null) { dialog.show(mainStage); } }); return toolBar; }
From source file:com.optimalbi.GUI.java
License:Apache License
private void saveSettings() { PrintWriter writer = null;/*from w w w .j a va 2 s .c om*/ currentRegions = new ArrayList<>(); currentRegions.addAll(allRegions.stream().filter(AmazonRegion::getActive).map(AmazonRegion::getRegion) .collect(Collectors.toList())); try { settingsFile.delete(); settingsFile.createNewFile(); writer = new PrintWriter(new FileWriter(settingsFile)); writer.print("regions "); for (Region r : currentRegions) { writer.print(r.getName() + ","); } writer.println(); writer.print("password " + encryptedPassword); } catch (IOException e) { logger.error("Failed to save settings " + e.getMessage()); labelCentre("Failed to save settings " + e.getMessage()); } finally { if (writer != null) { writer.flush(); writer.close(); } } }
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
public AmazonEC2Client connect(Region region, String awsAccessKey, String awsSecretKey) { AmazonEC2Client ec2Client;//from w w w .j a v a 2s .co m String endpoint = "ec2." + region.getName() + ".amazonaws.com"; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTPS); ec2Client = new AmazonEC2Client(credentials, clientConfig); ec2Client.setRegion(region); ec2Client.setEndpoint(endpoint); return ec2Client; }