http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/camel-notifications/src/main/resources/META-INF/spring/camel-context.xml ---------------------------------------------------------------------- diff --git a/camel-notifications/src/main/resources/META-INF/spring/camel-context.xml b/camel-notifications/src/main/resources/META-INF/spring/camel-context.xml deleted file mode 100644 index d52a694..0000000 --- a/camel-notifications/src/main/resources/META-INF/spring/camel-context.xml +++ /dev/null @@ -1,105 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> - -<!-- Configures the Camel Context--> - -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:camel="http://camel.apache.org/schema/spring" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - - <!-- Spring Property Placeholder configuration --> - <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> - <property name="location" value="classpath:org/jclouds/camel/notifier/camel.properties"/> - </bean> - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - - <propertyPlaceholder id="props" location="org/jclouds/camel/notifier/camel.properties"/> - - <route> - <from uri="quartz://cloud%3FTimer?trigger.repeatInterval=3600000&trigger.repeatCount=-1"/> - <to uri="jclouds:compute:{{jclouds.provider}}?operation=CamelJcloudsListNodes&nodeState=RUNNING"/> - <setHeader headerName="To"> - <simple>${email.to}</simple> - </setHeader> - <setHeader headerName="From"> - <simple>${email.from}</simple> - </setHeader> - <setHeader headerName="Subject"> - <constant>Running nodes in the cloud</constant> - </setHeader> - <filter> - <simple>${body.size} != 0</simple> - <setBody> - <groovy>request.body.collect { it.id }</groovy> - </setBody> - <to uri="smtps://{{smtp.server}}?username={{smtp.username}}&password={{smtp.password}}"/> - </filter> - </route> - - </camelContext> - - - <!-- Jclouds Component --> - <bean id="jclouds" class="org.apache.camel.component.jclouds.JcloudsComponent"> - <property name="computeServices"> - <list> - <ref bean="computeService"/> - </list> - </property> - </bean> - - <!-- Compute Service --> - <bean id="contextBuilder" class="org.jclouds.ContextBuilder" factory-method="newBuilder"> - <constructor-arg value="${jclouds.provider}"/> - </bean> - - <bean id="contextBuilderWithCreds" factory-bean="contextBuilder" factory-method="credentials"> - <constructor-arg value="${jclouds.identity}"/> - <constructor-arg value="${jclouds.credential}"/> - </bean> - - <bean id="contextBuilderWithModules" factory-bean="contextBuilderWithCreds" factory-method="modules"> - <constructor-arg name="modules"> - <list> - <bean class="org.jclouds.logging.slf4j.config.SLF4JLoggingModule"/> - </list> - </constructor-arg> - </bean> - - <bean id="contextBuilderWithOverrides" factory-bean="contextBuilderWithModules" factory-method="overrides"> - <constructor-arg name="overrides"> - <props> - <!-- TODO: add endpoint, but only if present --> - </props> - </constructor-arg> - </bean> - <bean id="computeCtx" factory-bean="contextBuilderWithOverrides" factory-method="buildView"> - <constructor-arg> - <value>org.jclouds.compute.ComputeServiceContext</value> - </constructor-arg> - </bean> - - <bean id="computeService" factory-bean="computeCtx" factory-method="getComputeService"/> - -</beans>
http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/camel-notifications/src/main/resources/logback.xml ---------------------------------------------------------------------- diff --git a/camel-notifications/src/main/resources/logback.xml b/camel-notifications/src/main/resources/logback.xml deleted file mode 100644 index a7b2c96..0000000 --- a/camel-notifications/src/main/resources/logback.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<configuration> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>- %msg%n</pattern> - </encoder> - </appender> - <root level="info"> - <appender-ref ref="STDOUT"/> - </root> - <logger name="jclouds.compute" level="debug"/> - <logger name="net.schmizz" level="warn"/> - <logger name="org.springframework" level="warn"/> -<!-- - <logger name="org.apache.camel" level="debug"/> - <logger name="jclouds.wire" level="debug"/> - <logger name="jclouds.headers" level="debug"/> - <logger name="jclouds.ssh" level="debug"/> ---> -</configuration> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/camel-notifications/src/main/resources/org/jclouds/camel/notifier/camel.properties ---------------------------------------------------------------------- diff --git a/camel-notifications/src/main/resources/org/jclouds/camel/notifier/camel.properties b/camel-notifications/src/main/resources/org/jclouds/camel/notifier/camel.properties deleted file mode 100644 index 22c754c..0000000 --- a/camel-notifications/src/main/resources/org/jclouds/camel/notifier/camel.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# - -jclouds.provider=${jclouds.provider} -jclouds.identity=${jclouds.identity} -jclouds.credential=${jclouds.credential} -smtp.username=${smtp.username} -smtp.server=${smtp.server} -smtp.password=${smtp.password} -email.from=${email.from} -email.to=${email.to} http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/chef-basics/pom.xml ---------------------------------------------------------------------- diff --git a/chef-basics/pom.xml b/chef-basics/pom.xml index 39853dc..49fec29 100644 --- a/chef-basics/pom.xml +++ b/chef-basics/pom.xml @@ -22,12 +22,12 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.jclouds.examples</groupId> <artifactId>chef-basics</artifactId> - <version>2.0.0</version> + <version>2.1.0</version> <name>chef-basics</name> <description>jclouds chef example that adds a node to a group, then installs an Apache web server on all nodes</description> <properties> - <jclouds.version>2.0.0</jclouds.version> + <jclouds.version>2.1.0</jclouds.version> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/cloudwatch-basics/README.md ---------------------------------------------------------------------- diff --git a/cloudwatch-basics/README.md b/cloudwatch-basics/README.md deleted file mode 100755 index aa4a8b2..0000000 --- a/cloudwatch-basics/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# cloudwatch-basics - -This is a simple example command line client to get the total metrics stored for each of your instances the past 24 hours and shows avg/max/min CPU utilization for each instance when possible. - -## Build - -Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. - -## Run - -Invoke the jar, passing your aws credentials. Here is an example: - -java -jar target/cloudwatch-basics-jar-with-dependencies.jar accessKeyId secretKey - -## License - -Copyright (C) 2009-2014 The Apache Software Foundation - -Licensed under the Apache License, Version 2.0 http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/cloudwatch-basics/pom.xml ---------------------------------------------------------------------- diff --git a/cloudwatch-basics/pom.xml b/cloudwatch-basics/pom.xml deleted file mode 100644 index 45a302f..0000000 --- a/cloudwatch-basics/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.jclouds.examples</groupId> - <artifactId>cloudwatch-basics</artifactId> - <version>1.0-SNAPSHOT</version> - <name>cloudwatch-basics</name> - <description>jclouds cloudwatch example</description> - - <dependencies> - <dependency> - <groupId>org.jclouds.provider</groupId> - <artifactId>aws-ec2</artifactId> - <version>1.5.0-beta.3</version> - </dependency> - <dependency> - <groupId>org.jclouds.provider</groupId> - <artifactId>aws-cloudwatch</artifactId> - <version>1.5.0-beta.3</version> - </dependency> - </dependencies> - - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <mainClass>org.jclouds.examples.cloudwatch.basics.MainApp</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <version>2.2.1</version> - <configuration> - <descriptors> - <descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor> - </descriptors> - <archive> - <manifest> - <mainClass>org.jclouds.examples.cloudwatch.basics.MainApp</mainClass> - </manifest> - </archive> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/cloudwatch-basics/src/main/assembly/jar-with-dependencies.xml ---------------------------------------------------------------------- diff --git a/cloudwatch-basics/src/main/assembly/jar-with-dependencies.xml b/cloudwatch-basics/src/main/assembly/jar-with-dependencies.xml deleted file mode 100644 index aaa208c..0000000 --- a/cloudwatch-basics/src/main/assembly/jar-with-dependencies.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> - <!-- copied from jar-with-dependencies (http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies) --> - <id>jar-with-dependencies</id> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <containerDescriptorHandlers> - <containerDescriptorHandler> - <handlerName>metaInf-services</handlerName> - </containerDescriptorHandler> - </containerDescriptorHandlers> - <dependencySets> - <dependencySet> - <outputDirectory>/</outputDirectory> - <useProjectArtifact>true</useProjectArtifact> - <unpack>true</unpack> - <scope>runtime</scope> - </dependencySet> - </dependencySets> -</assembly> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/cloudwatch-basics/src/main/java/org/jclouds/examples/cloudwatch/basics/MainApp.java ---------------------------------------------------------------------- diff --git a/cloudwatch-basics/src/main/java/org/jclouds/examples/cloudwatch/basics/MainApp.java b/cloudwatch-basics/src/main/java/org/jclouds/examples/cloudwatch/basics/MainApp.java deleted file mode 100644 index 0694279..0000000 --- a/cloudwatch-basics/src/main/java/org/jclouds/examples/cloudwatch/basics/MainApp.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.jclouds.examples.cloudwatch.basics; - -import com.google.common.collect.Iterators; -import org.jclouds.ContextBuilder; -import org.jclouds.aws.cloudwatch.AWSCloudWatchProviderMetadata; -import org.jclouds.aws.ec2.AWSEC2ProviderMetadata; -import org.jclouds.cloudwatch.CloudWatch; -import org.jclouds.cloudwatch.CloudWatchAsyncClient; -import org.jclouds.cloudwatch.CloudWatchClient; -import org.jclouds.cloudwatch.domain.Datapoint; -import org.jclouds.cloudwatch.domain.Dimension; -import org.jclouds.cloudwatch.domain.EC2Constants; -import org.jclouds.cloudwatch.domain.GetMetricStatistics; -import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; -import org.jclouds.cloudwatch.domain.Namespaces; -import org.jclouds.cloudwatch.domain.Statistics; -import org.jclouds.cloudwatch.domain.Unit; -import org.jclouds.cloudwatch.features.MetricClient; -import org.jclouds.cloudwatch.options.ListMetricsOptions; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.domain.ComputeMetadata; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.rest.RestContext; - -import java.text.DecimalFormat; -import java.util.Date; -import java.util.Iterator; -import java.util.Set; - -/** - * Demonstrates the use of {@link org.jclouds.cloudwatch.features.MetricClient}. - */ -public class MainApp { - - public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: accesskeyid secretkey"; - public static int PARAMETERS = 2; - - public static void main(String[] args) { - - if (args.length < PARAMETERS) { - throw new IllegalArgumentException(INVALID_SYNTAX); - } - - // Arguments - String accessKeyId = args[0]; - String secretKey = args[1]; - - ComputeServiceContext awsEC2Context = null; - RestContext<CloudWatchClient, CloudWatchAsyncClient> cloudWatchContext = null; - - try { - cloudWatchContext = ContextBuilder.newBuilder(new AWSCloudWatchProviderMetadata()) - .credentials(accessKeyId, secretKey) - .build(); - awsEC2Context = ContextBuilder.newBuilder(new AWSEC2ProviderMetadata()) - .credentials(accessKeyId, secretKey) - .build(ComputeServiceContext.class); - - // Get all nodes - Set<? extends ComputeMetadata> allNodes = awsEC2Context.getComputeService().listNodes(); - - for (ComputeMetadata node : allNodes) { - String nodeId = node.getProviderId(); - String region = getRegion(node.getLocation()); - MetricClient metricClient = cloudWatchContext.getApi().getMetricClientForRegion(region); - int metricsCount = getMetricsCountForInstance(cloudWatchContext.getApi(), region, nodeId); - double[] cpuUtilization = getCPUUtilizationStatsForInstanceOverTheLast24Hours(metricClient, nodeId); - String cpuUtilizationHeader = " CPU utilization statistics: "; - DecimalFormat df = new DecimalFormat("#.##"); - - System.out.println(nodeId + " CloudWatch Metrics (Past 24 hours)"); - System.out.println(" Total metrics stored: " + metricsCount); - - if (cpuUtilization == null) { - System.out.println(cpuUtilizationHeader + "Unable to compute as there are no CPU utilization " + - "metrics stored."); - } else { - System.out.println(cpuUtilizationHeader + - df.format(cpuUtilization[0]) + "% (avg), " + - df.format(cpuUtilization[1]) + "% (max), " + - df.format(cpuUtilization[2]) + "% (min)"); - } - } - } finally { - if (awsEC2Context != null) { - awsEC2Context.close(); - } - if (cloudWatchContext != null) { - cloudWatchContext.close(); - } - } - - } - - /** - * Returns the count of metrics stored for the given nodeId and region. - * - * @param cloudWatchClient the cloud watch client (Will use MetricsClient when Issue 922 is fixed) - * @param region the region the instance is in - * @param nodeId the instance id - * - * @return the total count of metrics stored for the given instance id and region - */ - private static int getMetricsCountForInstance(CloudWatchClient cloudWatchClient, String region, String nodeId) { - // Uses CloudWatchClient+region instead of MetricsClient because the pagination helper only works with - // CloudWatchClient: http://code.google.com/p/jclouds/issues/detail?id=922 - return Iterators.size(CloudWatch.listMetrics(cloudWatchClient, - region, - ListMetricsOptions.builder() - // Only return metrics for the given instance - .dimension(new Dimension( - EC2Constants.Dimension.INSTANCE_ID, - nodeId)) - .build()).iterator()); - } - - /** - * Return an array of doubles with the CPUUtilization {@link EC2Constants.MetricName#CPU_UTILIZATION} - * average, maximum and minimum values in respective order over the last 24 hours. - * - * @param metricClient the {@link MetricClient} to use - * @param nodeId the instance id whose CPUUtilization statistics we're intersted in calculating - * - * @return the array of doubles describe above or null if there are no CPUUtilization metrics stored for the given - * instance id over the past 24 hours - */ - private static double[] getCPUUtilizationStatsForInstanceOverTheLast24Hours(MetricClient metricClient, - String nodeId) { - - Dimension instanceIdDimension = new Dimension(EC2Constants.Dimension.INSTANCE_ID, nodeId); - ListMetricsOptions lmOptions = ListMetricsOptions.builder() - // Only return metrics if they are CPUUtilization - .metricName(EC2Constants.MetricName.CPU_UTILIZATION) - // Only return metrics for the AWS/EC2 namespace - .namespace(Namespaces.EC2) - // Only return metrics for the given instance - .dimension(instanceIdDimension) - .build(); - - // Return null to indicate there are no CPUUtilization metrics stored for the given node id - if (Iterators.size(metricClient.listMetrics(lmOptions).iterator()) == 0) { - return null; - } - - Date endDate = new Date(); // Now - Date startDate = new Date(endDate.getTime() - (1000 * 60 * 60 * 24)); // One day ago - GetMetricStatistics statistics = GetMetricStatistics.builder() - // Specify the instance id you're interested in - .dimension(instanceIdDimension) - // Specify the metric name you're interested in - .metricName(EC2Constants.MetricName.CPU_UTILIZATION) - // Specify the namespace of the metric - .namespace(Namespaces.EC2) - // Populate the average statistic in the response - .statistic(Statistics.AVERAGE) - // Populate the maximum statistic in the response - .statistic(Statistics.MAXIMUM) - // Populate the minimum statistic in the response - .statistic(Statistics.MINIMUM) - // Specify the start time for the metric statistics you want - .startTime(startDate) - // Specify the end time for the metric statistics you want - .endTime(endDate) - // Specify the metric statistic granularity - .period(3600) - // Specify the unit the metric values should be in - .unit(Unit.PERCENT) - .build(); - GetMetricStatisticsResponse statisticsResponse = metricClient.getMetricStatistics(statistics); - double avg = 0d; - double max = 0d; - double min = 0d; - Iterator<Datapoint> datapointIterator = statisticsResponse.iterator(); - - while(datapointIterator.hasNext()) { - Datapoint datapoint = datapointIterator.next(); - Double dAvg = datapoint.getAverage(); - Double dMax = datapoint.getMaximum(); - Double dMin = datapoint.getMinimum(); - - if (dAvg != null) { - avg = ((avg + dAvg) / 2); - } - if (dMax != null) { - if (dMax > max) { - max = dMax; - } - } - if (dMin != null) { - if (dMin < min) { - min = dMin; - } - } - } - - return new double[]{avg, max, min}; - - } - - /** - * Returns the region as string for the given {@link Location}. - * - * @param location the location - * - * @return the region or null if the region cannot be found - */ - private static String getRegion(Location location) { - - // Just to be safe - if (location == null) { - return null; - } - - String region = null; - while(region == null && location.getParent() != null) { - if (location.getScope() == LocationScope.REGION) { - region = location.getId(); - } else { - location = location.getParent(); - } - } - return region; - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/compute-basics/pom.xml ---------------------------------------------------------------------- diff --git a/compute-basics/pom.xml b/compute-basics/pom.xml index f814b6f..088eb88 100644 --- a/compute-basics/pom.xml +++ b/compute-basics/pom.xml @@ -22,12 +22,12 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.jclouds.examples</groupId> <artifactId>compute-basics</artifactId> - <version>2.0.0</version> + <version>2.1.0</version> <name>compute-basics</name> <description>jclouds compute example that adds a node to a group, then executes "echo hello" on all nodes</description> <properties> - <jclouds.version>2.0.0</jclouds.version> + <jclouds.version>2.1.0</jclouds.version> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/compute-clojure/README.md ---------------------------------------------------------------------- diff --git a/compute-clojure/README.md b/compute-clojure/README.md deleted file mode 100644 index 0372b44..0000000 --- a/compute-clojure/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# compute-clojure - -Basic usage of org.jclouds.compute2 to create a node, execute commands and destroy the node. The example below uses Amazon EC2 as provider. - -## Build - -Ensure you have [Leiningen](http://github.com/technomancy/leiningen) installed, then execute 'lein deps' to grab the jclouds dependencies. - -## Run - - bash$ lein repl - user> (use 'org.jclouds.compute2) - user> (use 'compute-clojure.compute-examples) - user> (def compute (compute-service "aws-ec2" "AMAZON-IDENTITY" "AMAZON-CREDENTIAL" :slf4j :sshj)) - user> (create compute "example-node-group") - user> (exec compute "echo hello" "example-node-group" (get-credentials)) - user> (destroy compute "example-node-group") - -## License - -Copyright (C) 2009-2014 The Apache Software Foundation - -Licensed under the Apache License, Version 2.0 http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/compute-clojure/resources/logback.xml ---------------------------------------------------------------------- diff --git a/compute-clojure/resources/logback.xml b/compute-clojure/resources/logback.xml deleted file mode 100644 index 46429a6..0000000 --- a/compute-clojure/resources/logback.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<configuration> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>- %msg%n</pattern> - </encoder> - </appender> - <root level="info"> - <appender-ref ref="STDOUT"/> - </root> - <logger name="jclouds.compute" level="debug"/> - <logger name="net.schmizz" level="warn"/> -<!-- - <logger name="jclouds.wire" level="debug"/> - <logger name="jclouds.headers" level="debug"/> - <logger name="jclouds.ssh" level="debug"/> ---> -</configuration> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/deploy-war-via-ant/README.md ---------------------------------------------------------------------- diff --git a/deploy-war-via-ant/README.md b/deploy-war-via-ant/README.md deleted file mode 100755 index 0128601..0000000 --- a/deploy-war-via-ant/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# deploy-war-via-ant - -This example uses the jclouds [ComputeService](http://code.google.com/p/jclouds/wiki/ComputeGuide) ant plugin to create a new virtual machine (node) and the [Cargo](http://cargo.codehaus.org/) plugin to deploy the web application. - -## Setup - -Ensure you have Ant 1.7.1 installed and in your path. Ex. - - wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.zip - - jar -xf apache-ant-1.7.1-bin.zip - - chmod 755 apache-ant-1.7.1/bin/* - - export PATH=apache-ant-1.7.1/bin:$PATH - - -Ensure you have jsch 0.1.42 is in $ANT_HOME/lib. Ex. - - cd apache-ant-1.7.1/lib - - wget https://sourceforge.net/projects/jsch/files/jsch/jsch-0.1.42.jar - -## Run - -### Deploying to localhost -Invoke 'ant justplaincargo' and this should deploy the webapp to http://localhost:8080/sample - -### Deploying to the cloud -Invoke 'ant' and supply parameters when asked, or as system properties. - -= provider - cloud you want to deploy to (ex. aws-ec2, cloudservers-us) - -= identity - your account on the cloud provider (ex. accesskey, username) - -= credential - your password on that account (ex. secretkey, password) - -= group - what to name the node that runs your webapp (ex. cargo-webapp) - -Ex. for Bluelock - -ant -Dprovider=bluelock-vcdirector [email protected] -Dcredential=password -Dgroup=cargo-webapp - -Ex. for Amazon EC2 - -ant -Dprovider=aws-ec2 -Didentity=accesskey -Dcredential=secretkey -Dgroup=cargo-webapp - - -Note that you should run 'ant destroy' to cleanup cloud nodes after you are finished. - -## License - -Copyright (C) 2009-2014 The Apache Software Foundation - -Licensed under the Apache License, Version 2.0 http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/deploy-war-via-ant/build.xml ---------------------------------------------------------------------- diff --git a/deploy-war-via-ant/build.xml b/deploy-war-via-ant/build.xml deleted file mode 100644 index 3871956..0000000 --- a/deploy-war-via-ant/build.xml +++ /dev/null @@ -1,111 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project xmlns:artifact="urn:maven-artifact-ant" name="cargooverssh" default="cargooverssh" basedir="."> - <property file="build.properties" /> - <property name="privatekeyfile" value="${user.home}/.ssh/id_rsa" /> - <property name="publickeyfile" value="${user.home}/.ssh/id_rsa.pub" /> - <property name="listenport" value="8080" /> - <property name="container.zip" value="http://apache.imghat.com//tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz" /> - <property name="warfile" value="build/sample.war" /> - - <!-- maven must be available before we use it --> - <delete dir="build/cargo"/> - <mkdir dir="build/cargo"/> - - <get src="http://opensource.become.com/apache//maven/binaries/maven-ant-tasks-2.1.3.jar" dest="build/maven-ant-tasks"/> - <get src="http://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/sample.war" dest="${warfile}"/> - - <input - message="Which provider would you like to use (aws-ec2, bluelock-vcdirector, cloudservers-uk, cloudservers-us, cloudsigma-zrh, eucalyptus-partnercloud-ec2, elastichosts-lon-b, elastichosts-lon-p, elastichosts-sat-p, gogrid, openhosting-east1, serverlove-z1-man, skalicloud-sdg-my, slicehost, trmk-ecloud, trmk-vcloudexpress, greenhousedata-element-vcloud)?" - validargs="aws-ec2,bluelock-vcdirector,cloudservers-uk,cloudservers-us,cloudsigma-zrh,eucalyptus-partnercloud-ec2,elastichosts-lon-b,elastichosts-lon-p,elastichosts-sat-p,gogrid,openhosting-east1,serverlove-z1-man,skalicloud-sdg-my,slicehost,trmk-ecloud,trmk-vcloudexpress" - addproperty="provider" - /> - - <!-- initialize maven tasks --> - <path id="maven-ant-tasks.classpath" path="build/maven-ant-tasks"/> - <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpathref="maven-ant-tasks.classpath"/> - - <!-- Setup maven so that we can get latest version of jclouds, jclouds, and jruby --> - <artifact:dependencies pathId="jclouds.classpath"> - <dependency groupid="com.jcraft" artifactId="jsch" version="0.1.44-1"/> - <dependency groupid="org.codehaus.cargo" artifactId="cargo-ant" version="1.0.6"/> - <dependency groupid="org.codehaus.cargo" artifactId="cargo-core-container-tomcat" version="1.0.6"/> - <dependency groupId="org.jclouds.provider" artifactId="${provider}" version="1.1.0" /> - <dependency groupId="org.jclouds" artifactId="jclouds-antcontrib" version="1.1.0" /> - </artifact:dependencies> - - <typedef name="compute" classname="org.jclouds.tools.ant.taskdefs.compute.ComputeTask" classpathref="jclouds.classpath" /> - <taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jclouds.classpath" /> - <taskdef resource="cargo.tasks" classpathref="jclouds.classpath"/> - - <input message="What is your identity on ${provider}?" addproperty="identity"/> - <input message="What is the credential for ${identity}?" addproperty="credential"/> - <input message="What is the group for the deployment?" addproperty="group" defaultvalue="cargo"/> - <property name="url" value="compute://${identity}:${credential}@${provider}"/> - - <target name="destroy" description="destroy the nodes ${group}"> - <compute actions="destroy" provider="${url}"> - <nodes group="${group}" /> - </compute> - <sleep seconds="5" /> - </target> - - <target name="create" description="create the nodes ${group}" > - <compute actions="destroy,create" provider="${url}"> - <nodes group="${group}" os="UBUNTU" hardware="SMALLEST" - runscript="runscript.sh" openports="22,${listenport}" - privatekeyfile="${privatekeyfile}" publickeyfile="${publickeyfile}" - hostproperty="host" usernameproperty="username" /> - </compute> - </target> - - <target name="cargooverssh" depends="create" description="run cargo on remote nodes" > - <echo message="deploying tomcat and sample app to to: http://${host}:${listenport}/sample/" /> - <echo message="note that eventhough cargo says ctrl-c stops the server, you really need to run ant destroy to kill it" /> - <cargo containerId="tomcat6x" output="build/output.log" log="build/cargo.log" action="start" timeout="600000"> - <zipurlinstaller installurl="${container.zip}" /> - <configuration home="build/cargo" type="standalone"> - <property name="cargo.java.home" value="/usr/lib/jvm/java-6-openjdk"/> - <property name="cargo.hostname" value="${host}"/> - <property name="cargo.servlet.port" value="${listenport}"/> - <property name="cargo.ssh.host" value="${host}"/> - <property name="cargo.ssh.username" value="${username}"/> - <property name="cargo.ssh.password" value=""/> - <property name="cargo.ssh.keyfile" value="${privatekeyfile}"/> - <property name="cargo.ssh.remotebase" value="/tmp/cargo"/> - <property name="cargo.logging" value="high"/> - <deployable type="war" file="${warfile}"/> - </configuration> - </cargo> - </target> - - <target name="justplaincargo" description="run cargo on local machine" > - <echo message="deploying tomcat and sample app to: http://localhost:${listenport}/samples/" /> - <cargo containerId="tomcat6x" output="build/output.log" log="build/cargo.log" action="start" timeout="600000"> - <zipurlinstaller installurl="${container.zip}" /> - <configuration home="build/cargo" type="standalone"> - <property name="cargo.servlet.port" value="${listenport}"/> - <property name="cargo.logging" value="high"/> - <deployable type="war" file="${warfile}"/> - </configuration> - </cargo> - </target> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/deploy-war-via-ant/runscript.sh ---------------------------------------------------------------------- diff --git a/deploy-war-via-ant/runscript.sh b/deploy-war-via-ant/runscript.sh deleted file mode 100644 index 58d2982..0000000 --- a/deploy-war-via-ant/runscript.sh +++ /dev/null @@ -1,27 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# - -echo nameserver 208.67.222.222 >> /etc/resolv.conf -apt-get update -qq -apt-get upgrade -y -qq -apt-get install -y -qq wget -apt-get install -y -qq openjdk-6-jdk -wget -q http://mirrors.axint.net/apache/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz -tar xzf apache-tomcat-6.0.32.tar.gz -mkdir -p /tmp/cargo/containers -chmod 1777 /tmp/cargo -mv apache-tomcat-6.0.32 /tmp/cargo/containers/tomcat6x http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-computeservice-spot/README.md ---------------------------------------------------------------------- diff --git a/ec2-computeservice-spot/README.md b/ec2-computeservice-spot/README.md deleted file mode 100755 index 994ebb9..0000000 --- a/ec2-computeservice-spot/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# ec2-computeservice-spot - -This is a simple example command line client that creates a spot instance in [EC2](http://code.google.com/p/jclouds/wiki/EC2) using the ComputeService interface. - -## Build - -Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the sample. - -Note you'll also need to ensure you have an ssh key in your home directory. - -## Run - -Invoke the jar, passing your aws credentials and the name you wish to create or destroy - -### Creating your Instance - -The create command will create a keypair, security group, and an instance in running state. - -java -jar target/ec2-computeservice-spot-jar-with-dependencies.jar accesskey secretkey groupname create - -### Destroying your Instance - -The destroy command will clear up the instance, key, and security group. - -java -jar target/ec2-computeservice-spot-jar-with-dependencies.jar accesskey secretkey groupname destroy - -## License - -Copyright (C) 2009-2014 The Apache Software Foundation - -Licensed under the Apache License, Version 2.0 http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-computeservice-spot/pom.xml ---------------------------------------------------------------------- diff --git a/ec2-computeservice-spot/pom.xml b/ec2-computeservice-spot/pom.xml deleted file mode 100644 index 4a2be31..0000000 --- a/ec2-computeservice-spot/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.jclouds.examples</groupId> - <artifactId>ec2-computeservice-spot</artifactId> - <version>1.0.0</version> - <name>ec2-computeservice-spot</name> - <description>jclouds ec2 example that creates a spot instance using the ComputeService</description> - - <dependencies> - <dependency> - <groupId>org.jclouds.provider</groupId> - <artifactId>aws-ec2</artifactId> - <version>1.1.0</version> - </dependency> - </dependencies> - - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.spot.MainApp</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.spot.MainApp</mainClass> - </manifest> - </archive> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-computeservice-spot/src/main/java/org/jclouds/examples/ec2/spot/MainApp.java ---------------------------------------------------------------------- diff --git a/ec2-computeservice-spot/src/main/java/org/jclouds/examples/ec2/spot/MainApp.java b/ec2-computeservice-spot/src/main/java/org/jclouds/examples/ec2/spot/MainApp.java deleted file mode 100755 index bf8b548..0000000 --- a/ec2-computeservice-spot/src/main/java/org/jclouds/examples/ec2/spot/MainApp.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.jclouds.examples.ec2.spot; - -import java.io.File; -import java.io.IOException; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.predicates.NodePredicates; -import org.jclouds.net.IPSocket; -import org.jclouds.predicates.InetSocketAddressConnect; -import org.jclouds.predicates.RetryablePredicate; - -import com.google.common.base.Charsets; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; - -/** - * This the Main class of an Application that demonstrates the use of the Amazon EC2 extensions by - * creating a small spot server. - * - * Usage is: java MainApp accesskeyid secretkey group command where command in create destroy - */ -public class MainApp { - - public static int PARAMETERS = 4; - public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: accesskeyid secretkey group command\nwhere command in create destroy"; - - public static void main(String[] args) { - - if (args.length < PARAMETERS) - throw new IllegalArgumentException(INVALID_SYNTAX); - - // Args - String accesskeyid = args[0]; - String secretkey = args[1]; - String group = args[2]; - String command = args[3]; - - // Init - ComputeService compute = new ComputeServiceContextFactory().createContext("aws-ec2", accesskeyid, secretkey) - .getComputeService(); - - // wait up to 60 seconds for ssh to be accessible - RetryablePredicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 60, - 1, 1, TimeUnit.SECONDS); - try { - if (command.equals("create")) { - - Template template = compute.templateBuilder().build(); - - template.getOptions().as(AWSEC2TemplateOptions.class) - // set the price as 3 cents/hr - .spotPrice(0.03f) - // authorize my ssh key - .authorizePublicKey( - Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa.pub"), - Charsets.UTF_8)); - - System.out.printf(">> running one spot node type(%s) with ami(%s) in group(%s)%n", template.getHardware() - .getProviderId(), template.getImage().getId(), group); - // run only a single node - NodeMetadata node = Iterables.getOnlyElement(compute.createNodesInGroup(group, 1, template)); - - System.out.printf("<< running node(%s)%n", node.getId()); - IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), node.getLoginPort()); - if (socketTester.apply(socket)) { - System.out.printf("<< socket ready [%s] node(%s)%n", socket, node.getId()); - System.out.printf("ssh to node with the following command:%n ssh %s@%s%n", - node.getCredentials().identity, socket.getAddress()); - System.exit(0); - } else { - System.out.printf("<< socket not ready [%s] node(%s)%n", socket, node.getId()); - } - } else if (command.equals("destroy")) { - System.out.printf(">> destroying nodes in group(%s)%n", group); - Set<? extends NodeMetadata> destroyed = compute.destroyNodesMatching(NodePredicates.inGroup(group)); - System.out.printf("<< destroyed(%d)%n", destroyed.size()); - System.exit(0); - } else { - System.err.println(INVALID_SYNTAX); - System.exit(1); - } - } catch (RunNodesException e) { - System.err.println(e.getMessage()); - for (NodeMetadata node : e.getNodeErrors().keySet()) - compute.destroyNode(node.getId()); - System.exit(1); - } catch (IOException e) { - System.err.println(e.getMessage()); - System.exit(1); - } finally { - compute.getContext().close(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-createlamp/README.md ---------------------------------------------------------------------- diff --git a/ec2-createlamp/README.md b/ec2-createlamp/README.md deleted file mode 100755 index 943f7db..0000000 --- a/ec2-createlamp/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# ec2-createlamp - -This is a simple example command line client that creates a lamp server and everything you need to do that in [EC2](http://code.google.com/p/jclouds/wiki/EC2) - -## Build - -Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the sample. - -## Run - -Invoke the jar, passing your aws credentials and the name you wish to create or destroy - -### Creating your Instance - -The create command will create a keypair, security group, and an instance. It also blocks until the web server is running. - -java -jar target/ec2-createlamp-jar-with-dependencies.jar accesskey secretkey create adrianalmighty - -### Destroying your Instance - -The destroy command will clear up the instance, key, and security group. - -java -jar target/ec2-createlamp-jar-with-dependencies.jar accesskey secretkey destroy adrianalmighty - -## License - -Copyright (C) 2009-2014 The Apache Software Foundation - -Licensed under the Apache License, Version 2.0 http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-createlamp/pom.xml ---------------------------------------------------------------------- diff --git a/ec2-createlamp/pom.xml b/ec2-createlamp/pom.xml deleted file mode 100644 index ab18342..0000000 --- a/ec2-createlamp/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.jclouds.examples</groupId> - <artifactId>ec2-createlamp</artifactId> - <version>1.0.0</version> - <name>ec2-createlamp</name> - <description>jclouds ec2 example that creates an instance and all you need to access it</description> - - <dependencies> - <dependency> - <groupId>org.jclouds.provider</groupId> - <artifactId>aws-ec2</artifactId> - <version>1.5.0</version> - </dependency> - </dependencies> - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.createlamp.MainApp</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.createlamp.MainApp</mainClass> - </manifest> - </archive> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-createlamp/src/main/java/org/jclouds/examples/ec2/createlamp/MainApp.java ---------------------------------------------------------------------- diff --git a/ec2-createlamp/src/main/java/org/jclouds/examples/ec2/createlamp/MainApp.java b/ec2-createlamp/src/main/java/org/jclouds/examples/ec2/createlamp/MainApp.java deleted file mode 100755 index 6a947a1..0000000 --- a/ec2-createlamp/src/main/java/org/jclouds/examples/ec2/createlamp/MainApp.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.jclouds.examples.ec2.createlamp; - -import static org.jclouds.ec2.options.RunInstancesOptions.Builder.asType; -import static org.jclouds.scriptbuilder.domain.Statements.exec; - -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.ContextBuilder; -import org.jclouds.ec2.EC2AsyncClient; -import org.jclouds.ec2.EC2Client; -import org.jclouds.ec2.domain.InstanceState; -import org.jclouds.ec2.domain.InstanceType; -import org.jclouds.ec2.domain.IpProtocol; -import org.jclouds.ec2.domain.KeyPair; -import org.jclouds.ec2.domain.Reservation; -import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.ec2.predicates.InstanceStateRunning; -import org.jclouds.predicates.InetSocketAddressConnect; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.RestContext; -import org.jclouds.scriptbuilder.ScriptBuilder; -import org.jclouds.scriptbuilder.domain.OsFamily; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import com.google.common.net.HostAndPort; - -/** - * This the Main class of an Application that demonstrates the use of the EC2Client by creating a - * small lamp server. - * - * Usage is: java MainApp accesskeyid secretkey command name where command in create destroy - */ -public class MainApp { - - public static int PARAMETERS = 4; - public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: accesskeyid secretkey command name\nwhere command in create destroy"; - - public static void main(String[] args) throws TimeoutException { - - if (args.length < PARAMETERS) - throw new IllegalArgumentException(INVALID_SYNTAX); - - // Args - String accesskeyid = args[0]; - String secretkey = args[1]; - String command = args[2]; - String name = args[3]; - - // Init - RestContext<EC2Client, EC2AsyncClient> context = ContextBuilder - .newBuilder("aws-ec2").credentials(accesskeyid, secretkey) - .build(); - - // Get a synchronous client - EC2Client client = context.getApi(); - - try { - if (command.equals("create")) { - - KeyPair pair = createKeyPair(client, name); - - RunningInstance instance = createSecurityGroupKeyPairAndInstance(client, name); - - System.out.printf("instance %s ready%n", instance.getId()); - System.out.printf("ip address: %s%n", instance.getIpAddress()); - System.out.printf("dns name: %s%n", instance.getDnsName()); - System.out.printf("login identity:%n%s%n", pair.getKeyMaterial()); - - } else if (command.equals("destroy")) { - destroySecurityGroupKeyPairAndInstance(client, name); - } else { - throw new IllegalArgumentException(INVALID_SYNTAX); - } - } finally { - // Close connecton - context.close(); - System.exit(0); - } - - } - - private static void destroySecurityGroupKeyPairAndInstance(EC2Client client, String name) { - try { - String id = findInstanceByKeyName(client, name).getId(); - System.out.printf("%d: %s terminating instance%n", System.currentTimeMillis(), id); - client.getInstanceServices().terminateInstancesInRegion(null, findInstanceByKeyName(client, name).getId()); - } catch (NoSuchElementException e) { - } catch (Exception e) { - e.printStackTrace(); - } - - try { - System.out.printf("%d: %s deleting keypair%n", System.currentTimeMillis(), name); - client.getKeyPairServices().deleteKeyPairInRegion(null, name); - } catch (Exception e) { - e.printStackTrace(); - } - - try { - System.out.printf("%d: %s deleting group%n", System.currentTimeMillis(), name); - client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, name); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static RunningInstance createSecurityGroupKeyPairAndInstance(EC2Client client, String name) - throws TimeoutException { - // create a new security group - createSecurityGroupAndAuthorizePorts(client, name); - - // create a new instance - RunningInstance instance = runInstance(client, name, name); - - // await for the instance to start - return blockUntilInstanceRunning(client, instance); - } - - static void createSecurityGroupAndAuthorizePorts(EC2Client client, String name) { - System.out.printf("%d: creating security group: %s%n", System.currentTimeMillis(), name); - client.getSecurityGroupServices().createSecurityGroupInRegion(null, name, name); - for (int port : new int[] { 80, 8080, 443, 22 }) { - client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null, name, IpProtocol.TCP, port, - port, "0.0.0.0/0"); - } - } - - static KeyPair createKeyPair(EC2Client client, String name) { - System.out.printf("%d: creating keypair: %s%n", System.currentTimeMillis(), name); - return client.getKeyPairServices().createKeyPairInRegion(null, name); - } - - static RunningInstance runInstance(EC2Client client, String securityGroupName, String keyPairName) { - String script = new ScriptBuilder() // lamp install script - .addStatement(exec("runurl run.alestic.com/apt/upgrade"))// - .addStatement(exec("runurl run.alestic.com/install/lamp"))// - .addStatement(exec("apt-get -y install openjdk-6-jdk"))// no license agreement! - .render(OsFamily.UNIX); - - System.out.printf("%d: running instance%n", System.currentTimeMillis()); - - Reservation<? extends RunningInstance> reservation = client.getInstanceServices().runInstancesInRegion(null, - null, // allow ec2 to chose an availability zone - "ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts - 1, // minimum instances - 1, // maximum instances - asType(InstanceType.M1_SMALL) // smallest instance size - .withKeyName(keyPairName) // key I created above - .withSecurityGroup(securityGroupName) // group I created above - .withUserData(script.getBytes())); // script to run as root - - return Iterables.getOnlyElement(reservation); - - } - - static RunningInstance blockUntilInstanceRunning(EC2Client client, RunningInstance instance) throws TimeoutException { - // create utilities that wait for the instance to finish - RetryablePredicate<RunningInstance> runningTester = new RetryablePredicate<RunningInstance>( - new InstanceStateRunning(client), 180, 5, TimeUnit.SECONDS); - - System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); - if (!runningTester.apply(instance)) - throw new TimeoutException("timeout waiting for instance to run: " + instance.getId()); - - instance = findInstanceById(client, instance.getId()); - - RetryablePredicate<HostAndPort> socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 300, - 1, TimeUnit.SECONDS); - System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); - if (!socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22))) - throw new TimeoutException("timeout waiting for ssh to start: " + instance.getIpAddress()); - - System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getIpAddress()); - - System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(), instance.getIpAddress()); - if (!socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 80))) - throw new TimeoutException("timeout waiting for http to start: " + instance.getIpAddress()); - - System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getIpAddress()); - return instance; - } - - private static RunningInstance findInstanceById(EC2Client client, String instanceId) { - // search my account for the instance I just created - Set<? extends Reservation<? extends RunningInstance>> reservations = client.getInstanceServices() - .describeInstancesInRegion(null, instanceId); // last parameter (ids) narrows the - // search - - // since we refined by instanceId there should only be one instance - return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); - } - - private static RunningInstance findInstanceByKeyName(EC2Client client, final String keyName) { - // search my account for the instance I just created - Set<? extends Reservation<? extends RunningInstance>> reservations = client.getInstanceServices() - .describeInstancesInRegion(null); - - // extract all the instances from all reservations - Set<RunningInstance> allInstances = Sets.newHashSet(); - for (Reservation<? extends RunningInstance> reservation : reservations) { - allInstances.addAll(reservation); - } - - // get the first one that has a keyname matching what I just created - return Iterables.find(allInstances, new Predicate<RunningInstance>() { - - public boolean apply(RunningInstance input) { - return input.getKeyName().equals(keyName) && input.getInstanceState() != InstanceState.TERMINATED; - } - - }); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-windows/README.md ---------------------------------------------------------------------- diff --git a/ec2-windows/README.md b/ec2-windows/README.md deleted file mode 100644 index f71fed7..0000000 --- a/ec2-windows/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Amazon EC2 Windows example -This example demonstrates how to start a Windows Server instance on Amazon -EC2 and obtain its randomly-generated Administrator password. Once you have -this, you can log in to the server via RDP. - -## Usage -After building the example with `mvn assembly:assembly`, you can launch it like -this: - -``` -java -jar target/ec2-windows-jar-with-dependencies.jar --identity $AWS_API_KEY --credential $AWS_SECRET_KEY <optional arguments> -``` - -Replace `$AWS_API_KEY` and `$AWS_SECRET_KEY` appropriately. - -The following optional arguments are recognized: - - * `--region <regionname>` - specify the EC2 region name to launch in - * `--instance-type <instancetype>` - specify the EC2 instance type - defaults - to `m1.small` - * `--image-pattern <pattern>` - specify the pattern to select the image - - this defaults to a pattern that will match the base, English, version of - the current (or recent) Windows Server release. - -The example will start the Windows instance, wait for the encrypted password -to become available, and then decrypt it. It will display the public IP -address, user name (which is always Administrator) and password - you can -provide these to the Remote Desktop client and log in to the new instance. - -Once the instance is started, the example will wait for you to hit Enter on -the command line. After hitting Enter, the new instance will be shut down. http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-windows/pom.xml ---------------------------------------------------------------------- diff --git a/ec2-windows/pom.xml b/ec2-windows/pom.xml deleted file mode 100644 index 2d2648a..0000000 --- a/ec2-windows/pom.xml +++ /dev/null @@ -1,161 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.jclouds.examples</groupId> - <artifactId>ec2-windows</artifactId> - <version>1.0-SNAPSHOT</version> - <name>ec2-windows</name> - <description>jclouds compute example starts a Windows node and returns the Administrator password</description> - - <dependencies> - <dependency> - <groupId>org.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>1.5.0-beta.1</version> - </dependency> - <dependency> - <groupId>org.jclouds.provider</groupId> - <artifactId>aws-ec2</artifactId> - <version>1.5.0-beta.1</version> - </dependency> - <dependency> - <groupId>org.bouncycastle</groupId> - <artifactId>bcprov-jdk16</artifactId> - <version>1.46</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.jclouds.driver</groupId> - <artifactId>jclouds-bouncycastle</artifactId> - <version>1.5.0-beta.1</version> - <exclusions> - <!-- bouncy castle is a provider, so - it must be signed and used as-is. - we are doing this to prevent its - classes from getting into the - jar-with-dependencies --> - <exclusion> - <groupId>org.bouncycastle</groupId> - <artifactId>bcprov-jdk16</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.jclouds.driver</groupId> - <artifactId>jclouds-sshj</artifactId> - <version>1.5.0-beta.1</version> - </dependency> - <dependency> - <groupId>org.jclouds.driver</groupId> - <artifactId>jclouds-slf4j</artifactId> - <version>1.5.0-beta.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.6.1</version> - </dependency> - <dependency> - <groupId>args4j</groupId> - <artifactId>args4j</artifactId> - <version>2.0.16</version> - </dependency> - </dependencies> - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <encoding>${project.build.sourceEncoding}</encoding> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.windows.MainApp</mainClass> - </manifest> - </archive> - </configuration> - </plugin> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <version>2.2.1</version> - <configuration> - <descriptors> - <descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor> - </descriptors> - <archive> - <manifest> - <mainClass>org.jclouds.examples.ec2.windows.MainApp</mainClass> - </manifest> - <manifestEntries> - <Class-Path>bcprov-jdk16.jar</Class-Path> - </manifestEntries> - </archive> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.3</version> - <executions> - <execution> - <id>copy</id> - <phase>package</phase> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <artifactItems> - <artifactItem> - <groupId>org.bouncycastle</groupId> - <artifactId>bcprov-jdk16</artifactId> - <overWrite>false</overWrite> - <destFileName>bcprov-jdk16.jar</destFileName> - </artifactItem> - </artifactItems> - <outputDirectory>${project.build.directory}</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>true</overWriteSnapshots> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-windows/src/main/assembly/jar-with-dependencies.xml ---------------------------------------------------------------------- diff --git a/ec2-windows/src/main/assembly/jar-with-dependencies.xml b/ec2-windows/src/main/assembly/jar-with-dependencies.xml deleted file mode 100644 index 5857f6a..0000000 --- a/ec2-windows/src/main/assembly/jar-with-dependencies.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> - <!-- copied from jar-with-dependencies (http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies) --> - <id>jar-with-dependencies</id> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <containerDescriptorHandlers> - <containerDescriptorHandler> - <handlerName>metaInf-services</handlerName> - </containerDescriptorHandler> - </containerDescriptorHandlers> - <dependencySets> - <dependencySet> - <outputDirectory>/</outputDirectory> - <useProjectArtifact>true</useProjectArtifact> - <unpack>true</unpack> - <scope>runtime</scope> - </dependencySet> - </dependencySets> -</assembly> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/Arguments.java ---------------------------------------------------------------------- diff --git a/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/Arguments.java b/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/Arguments.java deleted file mode 100644 index 70317a1..0000000 --- a/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/Arguments.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.jclouds.examples.ec2.windows; - -import org.jclouds.ec2.domain.InstanceType; -import org.kohsuke.args4j.Option; - -/** - * A javabean that represents the application's command line arguments. - */ -public class Arguments { - private String identity; - private String credential; - private String region; - private static final String IMAGE_NAME_PATTERN_DEFAULT = "Windows_Server-2008-R2_SP1-English-64Bit-Base-"; - private String imageNamePattern = IMAGE_NAME_PATTERN_DEFAULT; - private static final String INSTANCE_TYPE_DEFAULT = InstanceType.M1_SMALL; - private String instanceType = INSTANCE_TYPE_DEFAULT; - private static final String AMI_OWNER_DEFAULT = "801119661308"; - private String amiOwner = AMI_OWNER_DEFAULT; - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - - public String getRegion() { - return region; - } - - public String getImageNamePattern() { - return imageNamePattern; - } - - public String getInstanceType() { - return instanceType; - } - - public String getAmiOwner() { - return amiOwner; - } - - @Option(name = "--identity", aliases = "-i", required = true, usage = "your AWS access key ID") - public void setIdentity(String identity) { - this.identity = identity; - } - - @Option(name = "--credential", aliases = "-c", required = true, usage = "your AWS secret access key") - public void setCredential(String credential) { - this.credential = credential; - } - - @Option(name = "--region", aliases = "-r", required = true, usage = "AWS region name") - public void setRegion(String region) { - this.region = region; - } - - @Option(name = "--image-pattern", aliases = "-p", usage = "regular expression to select an AMI; default=" + IMAGE_NAME_PATTERN_DEFAULT) - public void setImageNamePattern(String imageNamePattern) { - this.imageNamePattern = imageNamePattern; - } - - @Option(name = "--instance-type", aliases = "-t", usage = "instance type; default=" + INSTANCE_TYPE_DEFAULT) - public void setInstanceType(String instanceType) { - this.instanceType = instanceType; - } - - @Option(name = "--ami-owner", aliases = "-o", usage = "AMI owner account ID; default=" + AMI_OWNER_DEFAULT) - public void setAmiOwner(String amiOwner) { - this.amiOwner = amiOwner; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/934cdb08/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/MainApp.java ---------------------------------------------------------------------- diff --git a/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/MainApp.java b/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/MainApp.java deleted file mode 100644 index 8aa200b..0000000 --- a/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/MainApp.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.jclouds.examples.ec2.windows; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import com.google.inject.Module; -import org.jclouds.ContextBuilder; -import org.jclouds.aws.ec2.reference.AWSEC2Constants; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.domain.Location; -import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule; -import org.jclouds.location.predicates.LocationPredicates; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; - -import javax.annotation.Nullable; -import java.util.Properties; -import java.util.Set; - -/** - * The main application. This will parse and validate the command line - * arguments, initialize a jclouds context, and then jump to {@link - * WindowsInstanceStarter}. - */ -public class MainApp { - - private ComputeServiceContext context; - private ComputeService computeService; - private Arguments arguments; - - public MainApp(Arguments arguments) { - this.arguments = arguments; - } - - public static void main(String[] args) throws Exception { - Arguments arguments = new Arguments(); - CmdLineParser parser = new CmdLineParser(arguments); - try { - parser.parseArgument(args); - } catch (CmdLineException e) { - // handling of wrong arguments - System.err.println(e.getMessage()); - parser.printUsage(System.err); - System.exit(1); - } - new MainApp(arguments).run(); - } - - private void run() throws Exception { - Properties overrides = new Properties(); - overrides.put(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "owner-id=" + arguments.getAmiOwner() + ";state=available;image-type=machine"); - - ImmutableSet<Module> modules = ImmutableSet.<Module>of( - new SLF4JLoggingModule(), // OverThere uses SLF4J so we will as well - new BouncyCastleCryptoModule() // needed to decrypt the password from EC2 - ); - context = ContextBuilder.newBuilder("aws-ec2") - .credentials(arguments.getIdentity(), arguments.getCredential()) - .overrides(overrides) - .modules(modules) - .build(ComputeServiceContext.class); - - try { - computeService = context.getComputeService(); - Set<String> regions = Sets.newHashSet(Iterables.transform(Iterables.filter(computeService.listAssignableLocations(), LocationPredicates.isRegion()), new Function<Location, String>() { - @Override - public String apply(@Nullable Location location) { - return (location != null) ? location.getId() : null; - } - })); - - if (!regions.contains(arguments.getRegion())) { - System.err.println("Region \"" + arguments.getRegion() + "\" is not known. Known regions are:"); - for (String r : regions) { - System.err.println(" " + r); - } - System.exit(1); - } - - WindowsInstanceStarter app = new WindowsInstanceStarter(arguments, context); - app.run(); - } finally { - context.close(); - } - } - -}
