List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:apphub.storage.s3.CustomStorage.java
License:Open Source License
protected static AmazonS3 createS3(URL url) { AmazonS3 s3;/*w w w . j a v a 2 s .c om*/ String userInfo = url.getUserInfo(); if (userInfo != null) { String[] creds = userInfo.split(":"); if (creds.length == 2) { s3 = new AmazonS3Client(new BasicAWSCredentials(creds[0], creds[1])); } else { throw new CreateStorageException(url.toString(), "Credentials for S3 storage must be in form of KEY:SECRET"); } } else { s3 = new AmazonS3Client(); } Map<String, String> queryParameters = UrlUtil.getQueryParameters(url); String region = queryParameters.get("region"); if (region != null) { s3.setRegion(Region.getRegion(Regions.fromName(region))); } String endpoint = queryParameters.get("endpoint"); if (endpoint != null) { s3.setEndpoint(endpoint); } return s3; }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.AWSEC2VMDeploymentWrapper.java
License:Open Source License
@Override public void deployResource(CloudResourceDescription description) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey-NULL"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonEC2Client cleint = new AmazonEC2Client(credentials); CreateImageRequest request = new CreateImageRequest(); request.setInstanceId(""); request.setName(""); CreateImageResult result = cleint.createImage(request); /*will be returned*/ result.getImageId(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.AWSEC2VMDeploymentWrapper.java
License:Open Source License
@Override public void undeployResource(String resourceID) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey-NULL"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonEC2Client cleint = new AmazonEC2Client(credentials); TerminateInstancesRequest request = new TerminateInstancesRequest(); List<String> idList = new ArrayList<String>(); idList.add(resourceID);/*from w ww . j a v a 2s. com*/ request.setInstanceIds(idList); TerminateInstancesResult result = cleint.terminateInstances(request); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.redmine.RedmineEC2DeploymentWrapper.java
License:Open Source License
@Override public void deployResource(CloudResourceDescription description) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey-NULL"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonEC2Client cleint = new AmazonEC2Client(credentials); RunInstancesRequest request = new RunInstancesRequest(); request.setImageId("ami-0b420162"); RunInstancesResult response = cleint.runInstances(request); return;//from www . jav a 2s . c o m response.getReservation().getInstances().get(0).getInstanceId(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.redmine.RedmineEC2DeploymentWrapper.java
License:Open Source License
@Override public void undeployResource(String resourceID) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey-NULL"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonEC2Client client = new AmazonEC2Client(credentials); StopInstancesRequest request = new StopInstancesRequest(); List<String> idList = new ArrayList<String>(); idList.add(resourceID);/*www . j a v a 2 s . c om*/ request.setInstanceIds(idList); StopInstancesResult result = client.stopInstances(request); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.AWSS3Deployer.java
License:Open Source License
@Path("/deploy") @POST/*from w ww. j a v a 2s . com*/ @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) /*@Override*/ public Response deploy(@QueryParam("descriptionid") String descriptionid) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client client = new AmazonS3Client(credentials); //String name = description.getAttributes().get("name"); String name = "ddweerasiri-test-bucket"; //client.createBucket(name); log.info("Bucket was created with name:" + name); System.out.println("Helooooooo:" + descriptionid); JsonObject json = new JsonObject(); json.addProperty("cloudResourceDescriptionId", descriptionid); return Response.status(Response.Status.OK).entity(json.toString()).build(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.AWSS3Deployer.java
License:Open Source License
@Override public void undeployResource(String resourceID) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client client = new AmazonS3Client(credentials); client.deleteBucket(resourceID);// w w w . j a v a 2 s . c o m Response.status(Response.Status.OK).entity(json.toString()).build(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.ClassForPaper.java
License:Open Source License
@Path("/deployResource") @POST/* w ww.ja v a 2s . co m*/ @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response deployResource(@QueryParam("description") CRCD resourceDescription) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client client = new AmazonS3Client(credentials); String name = resourceDescription.getAttribute("bucket-name"); Bucket bucket = client.createBucket(name); JsonObject json = new JsonObject(); json.addProperty("resourceID", bucket.getName()); return Response.status(Response.Status.OK).entity(json.toString()).build(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.ClassForPaper.java
License:Open Source License
@Path("/undeployResource") @POST/*from ww w .j a va 2 s . c om*/ @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response undeployResource(@QueryParam("resourceID") String resourceID) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client client = new AmazonS3Client(credentials); client.deleteBucket(resourceID); JsonObject json = new JsonObject(); json.addProperty("result", "Bucket:" + resourceID + "undeployed."); return Response.status(Response.Status.OK).entity(json.toString()).build(); }
From source file:awslabs.lab41.Lab41.java
License:Open Source License
public AWSCredentials getCredentials(String mode) throws IOException { AWSCredentials credentials = null;// w ww . j a v a 2 s . com String propFileName = "AwsCredentials.properties"; File propFile = new File(propFileName); if (!propFile.exists()) { throw new FileNotFoundException("File doesn't exist: " + propFile.getAbsolutePath()); } Properties properties = new Properties(); properties.load(new FileInputStream(propFile)); if (mode.toLowerCase().equals("prepmode")) { if (properties.getProperty("prepAccessKey") == null || properties.getProperty("prepSecretKey") == null) { throw new IllegalArgumentException("The specified file (" + propFile.getAbsolutePath() + ") " + "doesn't contain the expected properties 'prepAccessKey' and 'prepSecretKey'."); } credentials = new BasicAWSCredentials(properties.getProperty("prepAccessKey"), properties.getProperty("prepSecretKey")); } else if (mode.toLowerCase().equals("appmode")) { if (properties.getProperty("appAccessKey") == null || properties.getProperty("appSecretKey") == null) { throw new IllegalArgumentException("The specified file (" + propFile.getAbsolutePath() + ") " + "doesn't contain the expected properties 'appAccessKey' and 'appSecretKey'."); } // Store the appropriate credentials. credentials = new BasicAWSCredentials(properties.getProperty("appAccessKey"), properties.getProperty("appSecretKey")); } return credentials; }