Guest User

Cloudstack Plugin broken example

a guest
Apr 4th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. diff --git a/client/pom.xml b/client/pom.xml
  2. index 39d899e..a8f91ec 100644
  3. --- a/client/pom.xml
  4. +++ b/client/pom.xml
  5. @@ -217,6 +217,11 @@
  6. <artifactId>cloud-engine-storage-volume</artifactId>
  7. <version>${project.version}</version>
  8. </dependency>
  9. + <dependency>
  10. + <groupId>org.apache.cloudstack</groupId>
  11. + <artifactId>cloud-plugin-timeofday</artifactId>
  12. + <version>${project.version}</version>
  13. + </dependency>
  14. </dependencies>
  15. <build>
  16. <defaultGoal>install</defaultGoal>
  17. diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
  18. index a7b2f8b..ca5c75f 100644
  19. --- a/client/tomcatconf/commands.properties.in
  20. +++ b/client/tomcatconf/commands.properties.in
  21. @@ -540,3 +540,6 @@ listRegions=15
  22.  
  23. #### Baremetal commands
  24. addBaremetalHost=1
  25. +
  26. +#### plugin (timeofday)
  27. +getTimeOfDay=15
  28. diff --git a/plugins/pom.xml b/plugins/pom.xml
  29. index 60432a6..44b3f75 100755
  30. --- a/plugins/pom.xml
  31. +++ b/plugins/pom.xml
  32. @@ -34,6 +34,7 @@
  33. <modules>
  34. <module>api/rate-limit</module>
  35. <module>api/discovery</module>
  36. + <module>api/timeofday</module>
  37. <module>acl/static-role-based</module>
  38. <module>deployment-planners/user-concentrated-pod</module>
  39. <module>deployment-planners/user-dispersing</module>
  40.  
  41.  
  42. * NEW FILES *
  43.  
  44. plugins/api/timeofday/pom.xml
  45.  
  46. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  48. <modelVersion>4.0.0</modelVersion>
  49. <artifactId>cloud-plugin-timeofday</artifactId>
  50. <name>Apache CloudStack Plugin - TimeOfDay</name>
  51. <parent>
  52. <groupId>org.apache.cloudstack</groupId>
  53. <artifactId>cloudstack-plugins</artifactId>
  54. <version>4.1.0-SNAPSHOT</version>
  55. <relativePath>../../pom.xml</relativePath>
  56. </parent>
  57. <dependencies>
  58. <dependency>
  59. <groupId>org.apache.cloudstack</groupId>
  60. <artifactId>cloud-api</artifactId>
  61. <version>${project.version}</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>org.apache.cloudstack</groupId>
  65. <artifactId>cloud-utils</artifactId>
  66. <version>${project.version}</version>
  67. </dependency>
  68. <dependency>
  69. <groupId>mysql</groupId>
  70. <artifactId>mysql-connector-java</artifactId>
  71. <version>${cs.mysql.version}</version>
  72. <scope>provided</scope>
  73. </dependency>
  74. </dependencies>
  75. <build>
  76. <defaultGoal>install</defaultGoal>
  77. <sourceDirectory>src</sourceDirectory>
  78. <testSourceDirectory>test</testSourceDirectory>
  79. <plugins>
  80. <plugin>
  81. <artifactId>maven-surefire-plugin</artifactId>
  82. <configuration>
  83. <skipTests>true</skipTests>
  84. </configuration>
  85. <executions>
  86. <execution>
  87. <phase>integration-test</phase>
  88. <goals>
  89. <goal>test</goal>
  90. </goals>
  91. </execution>
  92. </executions>
  93. </plugin>
  94. </plugins>
  95. </build>
  96. </project>
  97.  
  98. * New File plugins/api/timeofday/src/com/cloud/test/TimeOfDayManager.java *
  99.  
  100. package com.cloud.test;
  101.  
  102. import com.cloud.utils.component.PluggableService;
  103.  
  104. public interface TimeOfDayManager extends PluggableService { }
  105.  
  106. * New File plugins/api/timeofday/src/com/cloud/test/TimeOfDayManagerImpl.java *
  107.  
  108. package com.cloud.test;
  109.  
  110. import com.cloud.utils.component.PluggableService;
  111.  
  112. import java.util.List;
  113. import java.util.ArrayList;
  114. import org.apache.log4j.Logger;
  115.  
  116. import com.cloud.test.GetTimeOfDayCmd;
  117.  
  118. import javax.annotation.PostConstruct;
  119. import org.springframework.stereotype.Component;
  120. import javax.ejb.Local;
  121.  
  122. @Component
  123. @Local(value = { TimeOfDayManager.class })
  124. public class TimeOfDayManagerImpl implements TimeOfDayManager {
  125. private static final Logger s_logger = Logger.getLogger(TimeOfDayManagerImpl.class);
  126.  
  127. public TimeOfDayManagerImpl() {
  128. super();
  129. }
  130.  
  131. @Override
  132. public List<Class<?>> getCommands() {
  133. List<Class<?>> cmdList = new ArrayList<Class<?>>();
  134. cmdList.add(GetTimeOfDayCmd.class);
  135. return cmdList;
  136. }
  137. }
  138.  
  139. * New File plugins/api/timeofday/src/com/cloud/test/GetTimeOfDayCmd.java *
  140.  
  141. package com.cloud.test;
  142.  
  143. import javax.inject.Inject;
  144. import org.apache.log4j.Logger;
  145.  
  146. import org.apache.cloudstack.api.BaseCmd;
  147. import org.apache.cloudstack.api.APICommand;
  148. import org.apache.cloudstack.api.Parameter;
  149.  
  150. @APICommand(name = "getTimeOfDay", description="Get Cloudstack's time of day", responseObject = GetTimeOfDayCmdResponse.class, includeInApiDoc=true)
  151. public class GetTimeOfDayCmd extends BaseCmd {
  152. public static final Logger s_logger = Logger.getLogger(GetTimeOfDayCmd.class.getName());
  153. private static final String s_name = "gettimeofdayresponse";
  154.  
  155. @Parameter(name="example", type=CommandType.STRING, required=false, description="Just an example string that will be uppercased")
  156. private String example;
  157.  
  158. public String getExample() {
  159. return this.example;
  160. }
  161.  
  162. @Override
  163. public void execute()
  164. {
  165. GetTimeOfDayCmdResponse response = new GetTimeOfDayCmdResponse();
  166. if ( this.example != null ) {
  167. response.setExampleEcho(example);
  168. }
  169.  
  170. response.setObjectName("timeofday"); // the inner part of the json structure
  171. response.setResponseName(getCommandName()); // the outer part of the json structure
  172.  
  173. this.setResponseObject(response);
  174. }
  175.  
  176. @Override
  177. public String getCommandName() {
  178. return s_name;
  179. }
  180.  
  181. @Override
  182. public long getEntityOwnerId() {
  183. return 0;
  184. }
  185. }
  186.  
  187. * NEW FILE plugins/api/timeofday/src/com/cloud/test/GetTimeOfDayCmdResponse.java *
  188.  
  189. package com.cloud.test;
  190.  
  191. import org.apache.cloudstack.api.ApiConstants;
  192. import com.cloud.serializer.Param;
  193. import com.google.gson.annotations.SerializedName;
  194. import org.apache.cloudstack.api.BaseResponse;
  195.  
  196. import java.util.Date;
  197. import java.text.SimpleDateFormat;
  198.  
  199. @SuppressWarnings("unused")
  200. public class GetTimeOfDayCmdResponse extends BaseResponse {
  201. @SerializedName(ApiConstants.IS_ASYNC) @Param(description="true if api is asynchronous")
  202. private Boolean isAsync;
  203. @SerializedName("timeOfDay") @Param(description="The time of day from CloudStack")
  204. private String timeOfDay;
  205. @SerializedName("exampleEcho") @Param(description="An upper cased string")
  206. private String exampleEcho;
  207.  
  208. public GetTimeOfDayCmdResponse(){
  209. this.isAsync = false;
  210.  
  211. SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
  212. this.setTimeOfDay( (new StringBuilder( dateformatYYYYMMDD.format( new Date() ) )).toString() );
  213. }
  214.  
  215. public void setAsync(Boolean isAsync) {
  216. this.isAsync = isAsync;
  217. }
  218.  
  219. public boolean getAsync() {
  220. return isAsync;
  221. }
  222.  
  223. public void setTimeOfDay(String timeOfDay) {
  224. this.timeOfDay = timeOfDay;
  225. }
  226.  
  227. public void setExampleEcho(String exampleEcho) {
  228. this.exampleEcho = exampleEcho.toUpperCase();
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment