Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lib/compile/awstasks-jsch-0.1.51-sources.jar
Binary file not shown.
Binary file removed lib/compile/awstasks-jsch-0.1.51.jar
Binary file not shown.
Binary file added lib/compile/awstasks-jsch-0.1.53-sources.jar
Binary file not shown.
Binary file added lib/compile/awstasks-jsch-0.1.53.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private AmazonEC2 createEc2() {
if (_region != null && !_region.trim().isEmpty()) {
ec2Client.setRegion(Region.getRegion(Regions.valueOf(_region.toUpperCase())));
}
LOG.info("connect to region " + _region);
return ec2Client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void doExecute(AmazonEC2 ec2) throws BuildException {
stopTask.setAccessKey(_accessKey);
stopTask.setAccessSecret(_accessSecret);
stopTask.setGroupName(_groupName);
stopTask.setRegion(_region);
stopTask.execute();
} catch (Exception stopException) {
throw startException;
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/datameer/awstasks/ant/ec2/Ec2TagTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package datameer.awstasks.ant.ec2;

import awstasks.com.amazonaws.services.ec2.AmazonEC2;
import awstasks.com.amazonaws.services.ec2.model.Tag;
import awstasks.com.amazonaws.services.ec2.model.Instance;
import awstasks.com.amazonaws.services.ec2.model.CreateTagsRequest;
import datameer.awstasks.aws.ec2.InstanceGroup;
import java.util.Map;
import java.util.HashMap;

public class Ec2TagTask extends AbstractEc2ConnectTask {

private String _key;
private String _value;

public void setTag(String tag)
{
String[] parts = tag.split("=");
_key = parts[0];
_value = parts[1];
}

@Override
protected void doExecute(AmazonEC2 ec2, InstanceGroup instanceGroup) throws Exception {
LOG.info("executing " + getClass().getSimpleName() + " with groupName '" + _groupName + "'");
for (Instance instance : instanceGroup.getInstances(false)) {
CreateTagsRequest createTagsRequest = new CreateTagsRequest();
createTagsRequest.withResources(instance.getInstanceId())
.withTags(new Tag(_key, _value));
ec2.createTags(createTagsRequest);
}
}
}
16 changes: 15 additions & 1 deletion src/main/java/datameer/awstasks/util/Ec2Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
import java.util.regex.Pattern;

import awstasks.com.amazonaws.auth.BasicAWSCredentials;
import awstasks.com.amazonaws.regions.Region;
import awstasks.com.amazonaws.regions.Regions;
import awstasks.com.amazonaws.services.ec2.AmazonEC2;
import awstasks.com.amazonaws.services.ec2.AmazonEC2Client;
import awstasks.com.amazonaws.services.ec2.model.RunInstancesRequest;
import awstasks.com.amazonaws.services.s3.AmazonS3;
import awstasks.com.amazonaws.services.s3.AmazonS3Client;


import datameer.awstasks.aws.ec2.InstanceGroup;
import datameer.awstasks.aws.ec2.InstanceGroupImpl;
import datameer.awstasks.aws.emr.EmrCluster;
Expand All @@ -49,12 +52,14 @@ public class Ec2Configuration {
private static final String ACCESS_KEY_SECRET = "ec2.accessSecret";
private static final String PRIVATE_KEY_NAME = "ec2.privateKeyName";
private static final String PRIVATE_KEY_FILE = "ec2.privateKeyFile";
private static final String REGION = "ec2.region";

private Properties _properties;
protected String _accessKeyId;
protected String _accessKeySecret;
protected String _privateKeyName;
protected String _privateKeyFile;
protected String _region;

/**
* Reads a ec2.properties from classpath. The path is {@link #EC2_PROPERTIES_FILE}.
Expand Down Expand Up @@ -84,6 +89,7 @@ public Ec2Configuration(String... files) throws IOException {
_accessKeySecret = _properties.getProperty(ACCESS_KEY_SECRET);
_privateKeyName = _properties.getProperty(PRIVATE_KEY_NAME);
_privateKeyFile = _properties.getProperty(PRIVATE_KEY_FILE);
_region = _properties.getProperty(REGION);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -144,6 +150,10 @@ public String getPrivateKeyFile() {
return _privateKeyFile;
}

public String getRegion() {
return _region;
}

public String getProperty(String name) {
String property = _properties.getProperty(name);
if (property == null) {
Expand All @@ -160,7 +170,11 @@ public RunInstancesRequest createLaunchConfiguration(String ami, String group, i
}

public AmazonEC2 createEc2() {
return new AmazonEC2Client(new BasicAWSCredentials(_accessKeyId, _accessKeySecret));
AmazonEC2Client ec2Client = new AmazonEC2Client(new BasicAWSCredentials(_accessKeyId, _accessKeySecret));
if (_region != null && !_region.trim().isEmpty()) {
ec2Client.setRegion(Region.getRegion(Regions.valueOf(_region.toUpperCase())));
}
return ec2Client;
}

public AmazonS3 createS3Service() {
Expand Down