本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2.setEndpoint方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2.setEndpoint方法的具體用法?Java AmazonEC2.setEndpoint怎麽用?Java AmazonEC2.setEndpoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.AmazonEC2
的用法示例。
在下文中一共展示了AmazonEC2.setEndpoint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createEc2Client
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public AmazonEC2 createEc2Client(String awsAccessId, String awsSecretKey) {
AWSCredentials credentials = new BasicAWSCredentials(awsAccessId, awsSecretKey);
ClientConfiguration configuration = createConfiguration();
AmazonEC2 client = new AmazonEC2Client(credentials, configuration);
if (host != null) {
client.setEndpoint(AmazonEC2.ENDPOINT_PREFIX + "." + host);
}
client = new ExceptionHandleAwsClientWrapper().wrap(client);
return client;
}
示例2: setDefaultRACList
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
/**
* Get the fist 3 available zones in the region
*/
public void setDefaultRACList(String region) {
AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
client.setEndpoint("ec2." + region + ".amazonaws.com");
DescribeAvailabilityZonesResult res = client.describeAvailabilityZones();
List<String> zone = Lists.newArrayList();
for (AvailabilityZone reg : res.getAvailabilityZones()) {
if (reg.getState().equals("available")) {
zone.add(reg.getZoneName());
}
if (zone.size() == 3) {
break;
}
}
DEFAULT_AVAILABILITY_ZONES = ImmutableList.copyOf(zone);
}
示例3: getConnector
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
private AmazonEC2 getConnector(IImage image, IProperty[] properties, IControllerServices controllerServices) {
AmazonEC2 connector = ConnectorLocator.getInstance().getConnector(properties, controllerServices);
if (image == null) {
return connector;
}
String region = Utils.getRegion(image.getProperties(), controllerServices);
if (!Strings.isNullOrEmpty(region)) {
region = region.toLowerCase();
connector.setEndpoint(regionVsURLs.get(region));
}
return connector;
}
示例4: getOwnIP
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static String getOwnIP()
{
AWSCredentials credentials = null;
try
{
credentials = new ProfileCredentialsProvider().getCredentials();
}
catch(Exception e){}
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
ec2.setEndpoint("ec2.eu-west-1.amazonaws.com");
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
ArrayList<Instance> listOfInstances = new ArrayList<Instance>();
for(Reservation reservation : reservations)
listOfInstances.addAll(reservation.getInstances());
String ownIP = null;
String ownInstanceID = checkInstanceId();
for(Instance instance: listOfInstances)
{
if(instance.getInstanceId().equals(ownInstanceID))
ownIP = instance.getPublicIpAddress();
}
return ownIP;
}
示例5: createInstances
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public void createInstances(int count, double priceLimitDollars) {
AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials());
ec2.setEndpoint(getOrCry("ec2endpoint"));
log.info("Requesting " + count + " instances of type "
+ getOrCry("ec2instancetype") + " with price limit of "
+ priceLimitDollars + " US$");
log.debug(startupScript);
try {
// our bid
RequestSpotInstancesRequest runInstancesRequest = new RequestSpotInstancesRequest()
.withSpotPrice(Double.toString(priceLimitDollars))
.withInstanceCount(count).withType("persistent");
// increase volume size
// BlockDeviceMapping mapping = new BlockDeviceMapping()
// .withDeviceName("/dev/sda1").withEbs(
// new EbsBlockDevice().withVolumeSize(Integer
// .parseInt(getOrCry("ec2disksize"))));
// what we want
LaunchSpecification workerSpec = new LaunchSpecification()
.withInstanceType(getOrCry("ec2instancetype"))
.withImageId(getOrCry("ec2ami"))
.withKeyName(getOrCry("ec2keypair"))
// .withBlockDeviceMappings(mapping)
.withUserData(
new String(Base64.encodeBase64(startupScript
.getBytes())));
runInstancesRequest.setLaunchSpecification(workerSpec);
// place the request
ec2.requestSpotInstances(runInstancesRequest);
log.info("Request placed, now use 'monitor' to check how many instances are running. Use 'shutdown' to cancel the request and terminate the corresponding instances.");
} catch (Exception e) {
log.warn("Failed to start instances - ", e);
}
}
示例6: shutdownInstances
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public void shutdownInstances() {
AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials());
ec2.setEndpoint(getOrCry("ec2endpoint"));
try {
// cancel spot request, so no new instances will be launched
DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest();
DescribeSpotInstanceRequestsResult describeResult = ec2
.describeSpotInstanceRequests(describeRequest);
List<SpotInstanceRequest> describeResponses = describeResult
.getSpotInstanceRequests();
List<String> spotRequestIds = new ArrayList<String>();
List<String> instanceIds = new ArrayList<String>();
for (SpotInstanceRequest describeResponse : describeResponses) {
spotRequestIds.add(describeResponse.getSpotInstanceRequestId());
if ("active".equals(describeResponse.getState())) {
instanceIds.add(describeResponse.getInstanceId());
}
}
ec2.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest()
.withSpotInstanceRequestIds(spotRequestIds));
log.info("Cancelled spot request");
if (instanceIds.size() > 0) {
ec2.terminateInstances(new TerminateInstancesRequest(
instanceIds));
log.info("Shut down " + instanceIds.size() + " instances");
}
} catch (Exception e) {
log.warn("Failed to shutdown instances - ", e);
}
}
示例7: getClient
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public AmazonEC2 getClient() {
AWSCredentials credentials = new Aws().getAwsCredentials();
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
String region = getUserProperty(AWS_REGION);
String endpoint = "https://ec2." + region + ".amazonaws.com"; //$NON-NLS-1$ //$NON-NLS-2$
ec2.setEndpoint(endpoint);
return ec2;
}
示例8: createEc2Client
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
/**
* Creates a client for EC2.
* @param targetProperties the target properties (not null)
* @return a non-null client
* @throws TargetException if properties are invalid
*/
public static AmazonEC2 createEc2Client( Map<String,String> targetProperties ) throws TargetException {
parseProperties( targetProperties );
// Configure the IaaS client
AWSCredentials credentials = new BasicAWSCredentials(
targetProperties.get(Ec2Constants.EC2_ACCESS_KEY),
targetProperties.get(Ec2Constants.EC2_SECRET_KEY));
AmazonEC2 ec2 = new AmazonEC2Client( credentials );
ec2.setEndpoint( targetProperties.get(Ec2Constants.EC2_ENDPOINT ));
return ec2;
}
示例9: load
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public AmazonEC2 load(Provider provider) {
String region = Optional.fromNullable(provider.getOptions().get(ProviderOptions.REGION))
.or(ProviderOptions.DEFAULT_REGION);
AWSCredentials credentials = new BasicAWSCredentials(provider.getAccessKey(), provider.getSecretKey());
AmazonEC2 client = new AmazonEC2Client(credentials, new ClientConfiguration()
.withUserAgent(PROVISIONR_USER_AGENT));
if (provider.getEndpoint().isPresent()) {
LOG.info("Using endpoint {} as configured", provider.getEndpoint().get());
client.setEndpoint(provider.getEndpoint().get());
} else {
LOG.info(">> Searching endpoint for region {}", region);
DescribeRegionsRequest request = new DescribeRegionsRequest().withRegionNames(region);
DescribeRegionsResult result = client.describeRegions(request);
checkArgument(result.getRegions().size() == 1, "Invalid region name %s. Expected one result found %s",
region, result.getRegions());
LOG.info("<< Using endpoint {} for region {}", result.getRegions().get(0).getEndpoint(), region);
client.setEndpoint(result.getRegions().get(0).getEndpoint());
}
return client;
}
示例10: getConnection
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
private AmazonEC2 getConnection(String accessKey, String secretKey, Properties properties) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonEC2 conn = new AmazonEC2Client(credentials);
conn.setEndpoint(properties.getProperty("aws.endpoint"));
return conn;
}
示例11: CreateServer
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static String CreateServer(String keys, JSONObject endpointsAPI, String imageId, String typeId, String keypair)
{
String instanceId = null;
String accessKey = keys.split(";")[0];
String secretKey = keys.split(";")[1];
String regionEndpoint = (String) endpointsAPI.get("amazon-regionEndpoint");
try
{
// EC2 Client for given region and credentials
AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
ec2.setEndpoint(regionEndpoint);
RunInstancesRequest req = new RunInstancesRequest();
req.withInstanceType(typeId);
req.withImageId(imageId);
req.withMinCount(1).withMaxCount(1);
req.withSecurityGroups("securityGroup");
req.withKeyName(keypair);
// Execute run instance request and return ID of first (and only) instance
RunInstancesResult runInstances = ec2.runInstances(req);
instanceId = runInstances.getReservation().getInstances().get(0).getInstanceId();
}
catch (AmazonServiceException ase)
{
System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
instanceId = "MSG_FAILED";
}
catch (AmazonClientException ace)
{
System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
instanceId = "MSG_FAILED";
}
return instanceId;
}
示例12: StopServer
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static void StopServer(String keys, JSONObject endpointsAPI, String serverId)
{
String accessKey = keys.split(";")[0];
String secretKey = keys.split(";")[1];
String regionEndpoint = (String) endpointsAPI.get("amazon-regionEndpoint");
try
{
// EC2 Client for given region and credentials
AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
ec2.setEndpoint(regionEndpoint);
StopInstancesRequest req = new StopInstancesRequest();
ArrayList<String> list = new ArrayList<String>();
list.add(serverId);
req.setInstanceIds(list);
System.out.println("Stopping Instance " + serverId);
ec2.stopInstances(req);
return;
}
catch (AmazonServiceException ase)
{
System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
return;
}
catch (AmazonClientException ace)
{
System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
return;
}
}
示例13: StartServer
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static void StartServer(String keys, JSONObject endpointsAPI, String serverId)
{
String accessKey = keys.split(";")[0];
String secretKey = keys.split(";")[1];
String regionEndpoint = (String) endpointsAPI.get("amazon-regionEndpoint");
try
{
// EC2 Client for given region and credentials
AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
ec2.setEndpoint(regionEndpoint);
StartInstancesRequest req = new StartInstancesRequest();
ArrayList<String> list = new ArrayList<String>();
list.add(serverId);
req.setInstanceIds(list);
System.out.println("Starting Instance " + serverId);
ec2.startInstances(req);
return;
}
catch (AmazonServiceException ase)
{
System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
return;
}
catch (AmazonClientException ace)
{
System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
return;
}
}
示例14: getEc2Client
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
private AmazonEC2 getEc2Client() {
AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
client.setEndpoint("ec2." + config.getDC() + ".amazonaws.com");
return client;
}
示例15: getEc2Client
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
protected AmazonEC2 getEc2Client() {
AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider());
client.setEndpoint("ec2." + config.getDC() + ".amazonaws.com");
return client;
}