Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ROO-2986: Post 1.2.0.RELEASE code refactor and clean up - applied ER …

…cleanup profile
  • Loading branch information...
commit fb3e99c4b2b9bb43ec19b799620c05d01854f4bb 1 parent fc1f2ca
Alan Stewart authored
Showing with 9,606 additions and 9,581 deletions.
  1. +5 −6 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupCommands.java
  2. +2 −2 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupOperations.java
  3. +19 −21 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupOperationsImpl.java
  4. +3 −5 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/AppCloudClientFactoryImpl.java
  5. +94 −91 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudCredentials.java
  6. +136 −137 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryCommands.java
  7. +41 −41 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryOperations.java
  8. +459 −457 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryOperationsImpl.java
  9. +8 −8 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundrySession.java
  10. +93 −95 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundrySessionImpl.java
  11. +95 −97 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudPreferences.java
  12. +24 −26 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/ShellTableRenderer.java
  13. +167 −169 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/UaaAwareAppCloudClient.java
  14. +6 −6 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudAppConverter.java
  15. +6 −6 ...ndry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudAppMemoryOptionConverter.java
  16. +6 −6 ...oundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudControllerUrlConverter.java
  17. +94 −93 ...undry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudDeployableFileConverter.java
  18. +14 −14 ...n-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudFileConverter.java
  19. +6 −6 ...d-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudLoginEmailConverter.java
  20. +6 −6 ...loud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudServiceConverter.java
  21. +6 −6 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/CloudUriConverter.java
  22. +8 −8 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/ConverterUtils.java
  23. +6 −6 ...ndry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/ServiceConfigurationConverter.java
  24. +8 −8 ...-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/converter/StringListConverter.java
  25. +0 −1  addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/model/CloudControllerUrl.java
  26. +3 −3 ...-cloud-foundry/src/test/java/org/springframework/roo/addon/cloud/foundry/AppCloudClientFactoryImplTest.java
  27. +5 −6 addon-cloud-foundry/src/test/java/org/springframework/roo/addon/cloud/foundry/CloudCredentialsTest.java
  28. +10 −10 addon-cloud-foundry/src/test/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryCommandsTest.java
  29. +23 −24 addon-cloud-foundry/src/test/java/org/springframework/roo/addon/cloud/foundry/CloudFoundrySessionImplTest.java
  30. +10 −10 ...ry/src/test/java/org/springframework/roo/addon/cloud/foundry/converter/CloudControllerUrlConverterTest.java
  31. +26 −27 addon-configurable/src/main/java/org/springframework/roo/addon/configurable/ConfigurableMetadata.java
  32. +19 −19 ...configurable/src/main/java/org/springframework/roo/addon/configurable/ConfigurableMetadataProviderImpl.java
  33. +0 −1  addon-creator/src/main/java/org/springframework/roo/addon/creator/CreatorCommands.java
  34. +0 −2  addon-creator/src/main/java/org/springframework/roo/addon/creator/CreatorOperationsImpl.java
  35. +0 −1  addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbManagedAnnotationValues.java
  36. +6 −7 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreCommands.java
  37. +465 −467 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreDatabaseListenerImpl.java
  38. +623 −610 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreMetadata.java
  39. +39 −39 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreMetadataProviderImpl.java
  40. +7 −7 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreOperations.java
  41. +96 −96 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreOperationsImpl.java
  42. +135 −135 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreTypeUtils.java
  43. +6 −7 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/IdentifierHolder.java
  44. +9 −9 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/converter/IncludeExcludeTablesConverter.java
  45. +12 −13 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/converter/SchemaConverter.java
  46. +20 −20 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/jdbc/ConnectionProvider.java
  47. +25 −25 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/jdbc/ConnectionProviderImpl.java
  48. +11 −11 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/CascadeAction.java
  49. +91 −86 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Column.java
  50. +157 −150 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Database.java
  51. +88 −85 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/DatabaseContentHandler.java
  52. +105 −105 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/DatabaseIntrospector.java
  53. +177 −177 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/DatabaseXmlUtils.java
  54. +22 −22 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/DbreModelService.java
  55. +136 −134 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/DbreModelServiceImpl.java
  56. +102 −94 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/ForeignKey.java
  57. +30 −31 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Index.java
  58. +25 −25 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/IndexColumn.java
  59. +60 −61 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Reference.java
  60. +13 −13 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Schema.java
  61. +0 −1  addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/SchemaContentHandler.java
  62. +2 −2 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/SchemaIntrospector.java
  63. +129 −129 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/Table.java
  64. +2 −2 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/TableType.java
  65. +2 −2 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/dialect/Dialect.java
  66. +5 −5 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/dialect/MySQLDialect.java
  67. +5 −5 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/model/dialect/SybaseDialect.java
  68. +0 −1  addon-dod/src/main/java/org/springframework/roo/addon/dod/DataOnDemandAnnotationValues.java
  69. +0 −1  addon-dod/src/main/java/org/springframework/roo/addon/dod/DataOnDemandCommands.java
  70. +1,143 −1,132 addon-dod/src/main/java/org/springframework/roo/addon/dod/DataOnDemandMetadata.java
  71. +187 −187 addon-dod/src/main/java/org/springframework/roo/addon/dod/DataOnDemandMetadataProviderImpl.java
  72. +27 −26 addon-dod/src/main/java/org/springframework/roo/addon/dod/DataOnDemandOperationsImpl.java
  73. +0 −1  addon-dod/src/main/java/org/springframework/roo/addon/dod/EmbeddedHolder.java
  74. +0 −1  addon-dod/src/main/java/org/springframework/roo/addon/dod/EmbeddedIdHolder.java
  75. +26 −27 addon-email/src/main/java/org/springframework/roo/addon/email/MailCommands.java
  76. +8 −8 addon-email/src/main/java/org/springframework/roo/addon/email/MailOperations.java
  77. +167 −169 addon-email/src/main/java/org/springframework/roo/addon/email/MailOperationsImpl.java
  78. +22 −23 addon-email/src/main/java/org/springframework/roo/addon/email/MailProtocol.java
  79. +4 −5 addon-equals/src/main/java/org/springframework/roo/addon/equals/EqualsAnnotationValues.java
  80. +0 −1  addon-equals/src/main/java/org/springframework/roo/addon/equals/EqualsCommands.java
  81. +14 −16 addon-equals/src/main/java/org/springframework/roo/addon/equals/EqualsMetadata.java
  82. +28 −27 addon-equals/src/main/java/org/springframework/roo/addon/equals/EqualsMetadataProviderImpl.java
  83. +4 −5 addon-equals/src/main/java/org/springframework/roo/addon/equals/EqualsOperationsImpl.java
  84. +8 −8 addon-equals/src/main/java/org/springframework/roo/addon/equals/ExcludeFieldsConverter.java
  85. +197 −196 addon-finder/src/main/java/org/springframework/roo/addon/finder/DynamicFinderServicesImpl.java
  86. +12 −13 addon-finder/src/main/java/org/springframework/roo/addon/finder/FieldToken.java
  87. +15 −16 addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderCommands.java
  88. +0 −1  addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderFieldTokenMissingException.java
  89. +48 −46 addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderMetadata.java
  90. +43 −40 addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderMetadataProviderImpl.java
  91. +2 −2 addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderOperations.java
  92. +134 −132 addon-finder/src/main/java/org/springframework/roo/addon/finder/FinderOperationsImpl.java
  93. +0 −1  addon-finder/src/main/java/org/springframework/roo/addon/finder/InvalidFinderException.java
  94. +5 −6 addon-finder/src/main/java/org/springframework/roo/addon/finder/QueryHolder.java
  95. +25 −21 addon-finder/src/main/java/org/springframework/roo/addon/finder/ReservedToken.java
  96. +30 −31 addon-finder/src/main/java/org/springframework/roo/addon/finder/ReservedTokenHolder.java
  97. +34 −35 addon-git/src/main/java/org/springframework/roo/addon/git/GitCommands.java
  98. +29 −29 addon-git/src/main/java/org/springframework/roo/addon/git/GitOperations.java
  99. +93 −92 addon-git/src/main/java/org/springframework/roo/addon/git/GitOperationsImpl.java
  100. +5 −6 addon-git/src/main/java/org/springframework/roo/addon/git/GitShellEventListener.java
  101. +26 −27 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtCommands.java
  102. +5 −5 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtFileManager.java
  103. +28 −30 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtFileManagerImpl.java
  104. +6 −6 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtOperations.java
  105. +546 −548 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtOperationsImpl.java
  106. +42 −44 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtPath.java
  107. +168 −168 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtProxyProperty.java
  108. +5 −6 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtTemplateDataHolder.java
  109. +3 −3 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtTemplateService.java
  110. +490 −483 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtTemplateServiceImpl.java
  111. +244 −231 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtType.java
  112. +47 −47 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtTypeService.java
  113. +593 −587 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtTypeServiceImpl.java
  114. +93 −91 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/GwtUtils.java
  115. +4 −4 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/RooGwtMirroredFrom.java
  116. +6 −6 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/RooGwtProxy.java
  117. +5 −5 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/RooGwtRequest.java
  118. +14 −15 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/TemplateResourceLoader.java
  119. +10 −11 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/locator/GwtLocatorMetadata.java
  120. +106 −106 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/locator/GwtLocatorMetadataProviderImpl.java
  121. +16 −16 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/proxy/GwtProxyMetadata.java
  122. +107 −108 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/proxy/GwtProxyMetadataProviderImpl.java
  123. +8 −8 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/request/GwtRequestMetadata.java
  124. +43 −43 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/request/GwtRequestMetadataNotificationListener.java
  125. +150 −152 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/request/GwtRequestMetadataProviderImpl.java
  126. +8 −9 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/scaffold/GwtScaffoldMetadata.java
  127. +51 −51 addon-gwt/src/main/java/org/springframework/roo/addon/gwt/scaffold/GwtScaffoldMetadataProviderImpl.java
  128. +1 −1  ...src/main/resources/org/springframework/roo/addon/gwt/module/client/scaffold/ScaffoldMobileApp-template.java
  129. +5 −5 addon-gwt/src/test/java/org/springframework/roo/addon/gwt/GwtPathTest.java
  130. +0 −1  addon-gwt/src/test/java/org/springframework/roo/addon/gwt/GwtProxyPropertyTest.java
  131. +18 −19 addon-gwt/src/test/java/org/springframework/roo/addon/gwt/request/GwtRequestMetadataTest.java
  132. +0 −1  addon-javabean/src/main/java/org/springframework/roo/addon/javabean/JavaBeanAnnotationValues.java
  133. +116 −111 addon-javabean/src/main/java/org/springframework/roo/addon/javabean/JavaBeanMetadata.java
  134. +76 −76 addon-javabean/src/main/java/org/springframework/roo/addon/javabean/JavaBeanMetadataProvider.java
  135. +3 −4 addon-jdbc/src/main/java/org/springframework/roo/addon/jdbc/polling/internal/CommonJdbcDriverProvider.java
  136. +12 −13 addon-jdbc/src/main/java/org/springframework/roo/addon/jdbc/polling/internal/PollingJdbcDriverManager.java
  137. +19 −20 addon-jms/src/main/java/org/springframework/roo/addon/jms/JmsCommands.java
  138. +1 −1  addon-jms/src/main/java/org/springframework/roo/addon/jms/JmsDestinationType.java
  139. +6 −6 addon-jms/src/main/java/org/springframework/roo/addon/jms/JmsOperations.java
  140. +162 −164 addon-jms/src/main/java/org/springframework/roo/addon/jms/JmsOperationsImpl.java
  141. +8 −9 addon-jpa/src/main/java/org/springframework/roo/addon/jpa/AbstractIdentifierServiceAwareMetadataProvider.java
  142. +2 −3 addon-jpa/src/main/java/org/springframework/roo/addon/jpa/DatabaseDotComOperationsImpl.java
  143. +2 −3 addon-jpa/src/main/java/org/springframework/roo/addon/jpa/GaeOperationsImpl.java
  144. +28 −30 addon-jpa/src/main/java/org/springframework/roo/addon/jpa/JdbcDatabase.java
Sorry, we could not display the entire diff because too many files (792) changed.
View
11 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupCommands.java
@@ -17,16 +17,15 @@
@Service
public class BackupCommands implements CommandMarker {
- // Fields
@Reference private BackupOperations backupOperations;
- @CliAvailabilityIndicator("backup")
- public boolean isBackupCommandAvailable() {
- return backupOperations.isBackupPossible();
- }
-
@CliCommand(value = "backup", help = "Backup your project to a zip file")
public String backup() {
return backupOperations.backup();
}
+
+ @CliAvailabilityIndicator("backup")
+ public boolean isBackupCommandAvailable() {
+ return backupOperations.isBackupPossible();
+ }
}
View
4 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupOperations.java
@@ -8,7 +8,7 @@
*/
public interface BackupOperations {
- boolean isBackupPossible();
-
String backup();
+
+ boolean isBackupPossible();
}
View
40 addon-backup/src/main/java/org/springframework/roo/addon/backup/BackupOperationsImpl.java
@@ -38,18 +38,12 @@
@Service
public class BackupOperationsImpl implements BackupOperations {
- // Constants
private static final Logger LOGGER = HandlerUtils
.getLogger(BackupOperationsImpl.class);
- // Fields
@Reference private FileManager fileManager;
@Reference private ProjectOperations projectOperations;
- public boolean isBackupPossible() {
- return projectOperations.isFocusedProjectAvailable();
- }
-
public String backup() {
Assert.isTrue(isBackupPossible(), "Project metadata unavailable");
@@ -58,33 +52,37 @@ public String backup() {
final String pattern = File.separatorChar == '\\' ? "yyyy-MM-dd_HH.mm.ss"
: "yyyy-MM-dd_HH:mm:ss";
final DateFormat df = new SimpleDateFormat(pattern);
- long start = System.nanoTime();
+ final long start = System.nanoTime();
ZipOutputStream zos = null;
try {
- File projectDirectory = new File(projectOperations
+ final File projectDirectory = new File(projectOperations
.getPathResolver().getFocusedIdentifier(Path.ROOT, "."));
- MutableFile file = fileManager.createFile(FileUtils
+ final MutableFile file = fileManager.createFile(FileUtils
.getCanonicalPath(new File(projectDirectory,
projectOperations.getFocusedProjectName() + "_"
+ df.format(new Date()) + ".zip")));
zos = new ZipOutputStream(file.getOutputStream());
zip(projectDirectory, projectDirectory, zos);
}
- catch (FileNotFoundException e) {
+ catch (final FileNotFoundException e) {
LOGGER.fine("Could not determine project directory");
}
- catch (IOException e) {
+ catch (final IOException e) {
LOGGER.fine("Could not create backup archive");
}
finally {
IOUtils.closeQuietly(zos);
}
- long milliseconds = (System.nanoTime() - start) / 1000000;
+ final long milliseconds = (System.nanoTime() - start) / 1000000;
return "Backup completed in " + milliseconds + " ms";
}
+ public boolean isBackupPossible() {
+ return projectOperations.isFocusedProjectAvailable();
+ }
+
private void zip(final File directory, final File base,
final ZipOutputStream zos) throws IOException {
final File[] files = directory.listFiles(new FilenameFilter() {
@@ -104,25 +102,25 @@ public boolean accept(final File dir, final String name) {
}
});
- byte[] buffer = new byte[8192];
+ final byte[] buffer = new byte[8192];
int read = 0;
- for (int i = 0, n = files.length; i < n; i++) {
- if (files[i].isDirectory()) {
- if (files[i].listFiles().length == 0) {
- ZipEntry dirEntry = new ZipEntry(files[i].getPath()
+ for (final File file : files) {
+ if (file.isDirectory()) {
+ if (file.listFiles().length == 0) {
+ final ZipEntry dirEntry = new ZipEntry(file.getPath()
.substring(base.getPath().length() + 1)
+ File.separatorChar);
zos.putNextEntry(dirEntry);
}
- zip(files[i], base, zos);
+ zip(file, base, zos);
}
else {
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(
- files[i]));
- ZipEntry entry = new ZipEntry(files[i].getPath().substring(
- base.getPath().length() + 1));
+ file));
+ final ZipEntry entry = new ZipEntry(file.getPath()
+ .substring(base.getPath().length() + 1));
zos.putNextEntry(entry);
while ((read = inputStream.read(buffer)) != -1) {
zos.write(buffer, 0, read);
View
8 ...n-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/AppCloudClientFactoryImpl.java
@@ -24,19 +24,17 @@
@Service
public class AppCloudClientFactoryImpl implements AppCloudClientFactory {
- // Constants
private static final String CLOUD_FOUNDRY_PRODUCT_NAME = "Cloud Foundry Java API";
private static final String DEFAULT_BUNDLE_VERSION = "0.0.0.RELEASE";
- // Fields
- @Reference UaaService uaaService;
// TODO is this value ever used, or is it always overwritten by activate()?
private Product product = VersionHelper.getProduct(
CLOUD_FOUNDRY_PRODUCT_NAME, DEFAULT_BUNDLE_VERSION);
+ @Reference UaaService uaaService;
protected void activate(final ComponentContext context) {
- this.product = getCloudFoundryProduct(context.getBundleContext()
- .getBundle().getHeaders());
+ product = getCloudFoundryProduct(context.getBundleContext().getBundle()
+ .getHeaders());
}
private Product getCloudFoundryProduct(final Dictionary<?, ?> bundleHeaders) {
View
185 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudCredentials.java
@@ -14,29 +14,37 @@
*/
public class CloudCredentials {
- // Constants
private static final String EMAIL_KEY = "email";
private static final String PASSWORD_KEY = "password";
private static final String URL_KEY = "url";
- // Fields
+ public static CloudCredentials decode(final String encoded) {
+ if (StringUtils.isBlank(encoded)) {
+ throw new IllegalStateException(
+ "Stored login invalid; cannot continue");
+ }
+ final Map<String, String> map = new HashMap<String, String>();
+ final String[] encodedFields = encoded.split(",");
+ for (final String encodedField : encodedFields) {
+ final String[] valuePair = encodedField.split(":");
+ if (valuePair.length == 2) {
+ try {
+ map.put(valuePair[0],
+ new String(Base64.decode(valuePair[1],
+ Base64.DO_BREAK_LINES)));
+ }
+ catch (final IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ return new CloudCredentials(map);
+ }
+
private final String email;
private final String password;
- private final String url;
- /**
- * Constructor that accepts distinct values
- *
- * @param email the email address with which to log in (can be blank)
- * @param password the password for that email address (can be blank)
- * @param url the URL to log into (can be blank)
- */
- public CloudCredentials(final String email, final String password,
- final String url) {
- this.email = email;
- this.password = password;
- this.url = url;
- }
+ private final String url;
/**
* Constructor that reads the relevant entries of the given map
@@ -49,55 +57,17 @@ public CloudCredentials(final Map<String, String> properties) {
}
/**
- * Indicates whether these credentials are complete, i.e. contain enough
- * information to attempt a login
- *
- * @return see above
- */
- public boolean isValid() {
- return StringUtils.hasText(email) && StringUtils.hasText(password)
- && StringUtils.hasText(url);
- }
-
- public String getEmail() {
- return email;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getUrl() {
- return url;
- }
-
- /**
- * Indicates whether the given account details match these credentials
- *
- * @param url the URL to check (can be <code>null</code>)
- * @param email the email to check (can be <code>null</code>)
- * @return see above
- */
- public boolean isSameAccount(final String url, final String email) {
- return StringUtils.equals(url, this.url)
- && StringUtils.equals(email, this.email);
- }
-
- /**
- * Returns the URL for these credentials
+ * Constructor that accepts distinct values
*
- * @return <code>null</code> if none is set
+ * @param email the email address with which to log in (can be blank)
+ * @param password the password for that email address (can be blank)
+ * @param url the URL to log into (can be blank)
*/
- public URL getUrlObject() {
- if (StringUtils.hasText(this.url)) {
- try {
- return new URL(this.url);
- }
- catch (final MalformedURLException e) {
- throw new IllegalStateException(e);
- }
- }
- return null;
+ public CloudCredentials(final String email, final String password,
+ final String url) {
+ this.email = email;
+ this.password = password;
+ this.url = url;
}
public String encode() {
@@ -126,52 +96,85 @@ public String encode() {
return sb.toString();
}
- public static CloudCredentials decode(final String encoded) {
- if (StringUtils.isBlank(encoded)) {
- throw new IllegalStateException(
- "Stored login invalid; cannot continue");
- }
- final Map<String, String> map = new HashMap<String, String>();
- final String[] encodedFields = encoded.split(",");
- for (final String encodedField : encodedFields) {
- final String[] valuePair = encodedField.split(":");
- if (valuePair.length == 2) {
- try {
- map.put(valuePair[0],
- new String(Base64.decode(valuePair[1],
- Base64.DO_BREAK_LINES)));
- }
- catch (final IOException e) {
- throw new IllegalStateException(e);
- }
- }
- }
- return new CloudCredentials(map);
- }
-
@Override
public boolean equals(final Object o) {
- if (this == o)
+ if (this == o) {
return true;
- if (o == null || getClass() != o.getClass())
+ }
+ if ((o == null) || (getClass() != o.getClass())) {
return false;
+ }
final CloudCredentials clouldCredentials = (CloudCredentials) o;
if (email != null ? !email.equals(clouldCredentials.email)
- : clouldCredentials.email != null)
+ : clouldCredentials.email != null) {
return false;
+ }
if (url != null ? !url.equals(clouldCredentials.url)
- : clouldCredentials.url != null)
+ : clouldCredentials.url != null) {
return false;
+ }
return true;
}
+ public String getEmail() {
+ return email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * Returns the URL for these credentials
+ *
+ * @return <code>null</code> if none is set
+ */
+ public URL getUrlObject() {
+ if (StringUtils.hasText(url)) {
+ try {
+ return new URL(url);
+ }
+ catch (final MalformedURLException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return null;
+ }
+
@Override
public int hashCode() {
int result = email != null ? email.hashCode() : 0;
- result = 31 * result + (url != null ? url.hashCode() : 0);
+ result = (31 * result) + (url != null ? url.hashCode() : 0);
return result;
}
+
+ /**
+ * Indicates whether the given account details match these credentials
+ *
+ * @param url the URL to check (can be <code>null</code>)
+ * @param email the email to check (can be <code>null</code>)
+ * @return see above
+ */
+ public boolean isSameAccount(final String url, final String email) {
+ return StringUtils.equals(url, this.url)
+ && StringUtils.equals(email, this.email);
+ }
+
+ /**
+ * Indicates whether these credentials are complete, i.e. contain enough
+ * information to attempt a login
+ *
+ * @return see above
+ */
+ public boolean isValid() {
+ return StringUtils.hasText(email) && StringUtils.hasText(password)
+ && StringUtils.hasText(url);
+ }
}
View
273 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryCommands.java
@@ -30,9 +30,99 @@
@Service
public class CloudFoundryCommands implements CommandMarker {
- // Fields
@Reference CloudFoundryOperations cloudFoundryOperations;
+ @CliCommand(value = "cloud foundry list apps", help = "List deployed applications")
+ public void apps() {
+ cloudFoundryOperations.apps();
+ }
+
+ @CliCommand(value = "cloud foundry bind service", help = "Bind a service to a deployed application")
+ public void bindService(
+ @CliOption(key = "serviceName", mandatory = true, help = "The name of the service instance you want to bind") final CloudService service,
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application you want to bind the service to") final CloudApp appName) {
+
+ cloudFoundryOperations
+ .bindService(service.getName(), appName.getName());
+ }
+
+ @CliCommand(value = "cloud foundry clear login details", help = "Clears all stored login information")
+ public void clearStoredLoginDetails() {
+ cloudFoundryOperations.clearStoredLoginDetails();
+ }
+
+ // TODO: Add setup command once cloud namespace is more understood
+ // @CliCommand(value = "cloud foundry setup", help = "Setup Cloud Foundry")
+ public void config() {
+ cloudFoundryOperations.setup();
+ }
+
+ @CliCommand(value = "cloud foundry view crashes", help = "View recent application crashes")
+ public void crashes(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to view recent crashes for") final CloudApp appName) {
+
+ cloudFoundryOperations.crashes(appName.getName());
+ }
+
+ @CliCommand(value = "cloud foundry view crash logs", help = "Display all the logs for crashed instance")
+ public void crashLogs(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to view the crash logs for") final CloudApp appName,
+ @CliOption(key = "instance", mandatory = false, help = "The name specific instance of the application of interest") final String instance) {
+
+ cloudFoundryOperations.crashLogs(appName.getName(), instance);
+ }
+
+ @CliCommand(value = "cloud foundry create service", help = "Create a service instance")
+ public void createService(
+ @CliOption(key = "serviceType", mandatory = true, help = "The service type") final ServiceConfiguration service,
+ @CliOption(key = "serviceName", mandatory = true, help = "The name of your service instance") final String name,
+ @CliOption(key = "appName", mandatory = false, help = "The name of the app to bind the service to") final CloudApp bind) {
+
+ String appName = null;
+ if (bind != null) {
+ appName = bind.getName();
+ }
+ cloudFoundryOperations
+ .createService(service.getVendor(), name, appName);
+ }
+
+ @CliCommand(value = "cloud foundry delete app", help = "Delete an application")
+ public void delete(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to delete") final CloudApp appName) {
+
+ cloudFoundryOperations.delete(appName.getName());
+ }
+
+ @CliCommand(value = "cloud foundry delete service", help = "Delete a service")
+ public void deleteService(
+ @CliOption(key = "serviceName", mandatory = false, help = "The name of the service instance to delete") final CloudService service) {
+
+ cloudFoundryOperations.deleteService(service.getName());
+ }
+
+ @CliCommand(value = "cloud foundry files", help = "Directory listings or file download")
+ public void files(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to target") final CloudApp appName,
+ @CliOption(key = "path", mandatory = true, help = "The path of the file or folder to navigate to or view") final CloudFile path,
+ @CliOption(key = "instance", mandatory = false, help = "The specific instance of the application to be targeted") final String instance) {
+
+ cloudFoundryOperations.files(appName.getName(), path.getFileName(),
+ instance);
+ }
+
+ @CliCommand(value = "cloud foundry info", help = "Information")
+ public void info() {
+ cloudFoundryOperations.info();
+ }
+
+ @CliCommand(value = "cloud foundry list instances", help = "List and/or change the number of application instances")
+ public void instances(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to list and/or change the number instances for") final CloudApp appName,
+ @CliOption(key = "num", mandatory = false, help = "The number of instances to scale the application to") final String number) {
+
+ cloudFoundryOperations.instances(appName.getName(), number);
+ }
+
@CliAvailabilityIndicator({ "cloud foundry list apps",
"cloud foundry bind service", "cloud foundry view crash logs",
"cloud foundry view crashes", "cloud foundry create service",
@@ -50,11 +140,6 @@ public boolean isCommandAvailable() {
return cloudFoundryOperations.isCloudFoundryCommandAvailable();
}
- @CliCommand(value = "cloud foundry info", help = "Information")
- public void info() {
- cloudFoundryOperations.info();
- }
-
@CliCommand(value = "cloud foundry login", help = "Login")
public void login(
@CliOption(key = "email", mandatory = false, help = "The user's email address") final CloudLoginEmail loginEmail,
@@ -73,53 +158,20 @@ public void login(
cloudFoundryOperations.login(email, password, url);
}
- @CliCommand(value = "cloud foundry list services", help = "List of services available")
- public void services() {
- cloudFoundryOperations.services();
- }
-
- @CliCommand(value = "cloud foundry create service", help = "Create a service instance")
- public void createService(
- @CliOption(key = "serviceType", mandatory = true, help = "The service type") final ServiceConfiguration service,
- @CliOption(key = "serviceName", mandatory = true, help = "The name of your service instance") final String name,
- @CliOption(key = "appName", mandatory = false, help = "The name of the app to bind the service to") final CloudApp bind) {
-
- String appName = null;
- if (bind != null) {
- appName = bind.getName();
- }
- cloudFoundryOperations
- .createService(service.getVendor(), name, appName);
- }
-
- @CliCommand(value = "cloud foundry delete service", help = "Delete a service")
- public void deleteService(
- @CliOption(key = "serviceName", mandatory = false, help = "The name of the service instance to delete") final CloudService service) {
-
- cloudFoundryOperations.deleteService(service.getName());
- }
-
- @CliCommand(value = "cloud foundry bind service", help = "Bind a service to a deployed application")
- public void bindService(
- @CliOption(key = "serviceName", mandatory = true, help = "The name of the service instance you want to bind") final CloudService service,
- @CliOption(key = "appName", mandatory = true, help = "The name of the application you want to bind the service to") final CloudApp appName) {
+ @CliCommand(value = "cloud foundry view logs", help = "Display all the logs for a specific application")
+ public void logs(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to view the logs for") final CloudApp appName,
+ @CliOption(key = "instance", mandatory = false, help = "The name specific instance of the application of interest") final String instance) {
- cloudFoundryOperations
- .bindService(service.getName(), appName.getName());
+ cloudFoundryOperations.logs(appName.getName(), instance);
}
- @CliCommand(value = "cloud foundry unbind service", help = "Unbind a service from a deployed application")
- public void unbindService(
- @CliOption(key = "serviceName", mandatory = true, help = "The name of the service instance you want to bind") final CloudService service,
- @CliOption(key = "appName", mandatory = true, help = "The name of the application you want to bind the service to") final CloudApp appName) {
-
- cloudFoundryOperations.unbindService(service.getName(),
- appName.getName());
- }
+ @CliCommand(value = "cloud foundry map url", help = "Register an application with a URL")
+ public void mapUrl(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to bind the URL to") final CloudApp appName,
+ @CliOption(key = "url", mandatory = true, help = "The URL to bind the application to") final String url) {
- @CliCommand(value = "cloud foundry list apps", help = "List deployed applications")
- public void apps() {
- cloudFoundryOperations.apps();
+ cloudFoundryOperations.map(appName.getName(), url);
}
@CliCommand(value = "cloud foundry deploy", help = "Deploy an application")
@@ -138,18 +190,14 @@ public void push(
path.getPath(), urls);
}
- @CliCommand(value = "cloud foundry start app", help = "Start an application")
- public void start(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to start") final CloudApp appName) {
-
- cloudFoundryOperations.start(appName.getName());
- }
-
- @CliCommand(value = "cloud foundry stop app", help = "Stop an application")
- public void stop(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to stop") final CloudApp appName) {
+ // TODO: This feature was not working in the initial release JT
+ // @CliCommand(value = "cloud foundry rename app", help =
+ // "Delete an application")
+ public void renameApp(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to rename") final CloudApp appName,
+ @CliOption(key = "newAppName", mandatory = true, help = "The new name of the application") final String newAppName) {
- cloudFoundryOperations.stop(appName.getName());
+ cloudFoundryOperations.renameApp(appName.getName(), newAppName);
}
@CliCommand(value = "cloud foundry restart app", help = "Restart an application")
@@ -159,36 +207,40 @@ public void restart(
cloudFoundryOperations.restart(appName.getName());
}
- @CliCommand(value = "cloud foundry delete app", help = "Delete an application")
- public void delete(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to delete") final CloudApp appName) {
+ @CliCommand(value = "cloud foundry list services", help = "List of services available")
+ public void services() {
+ cloudFoundryOperations.services();
+ }
- cloudFoundryOperations.delete(appName.getName());
+ @CliCommand(value = "cloud foundry start app", help = "Start an application")
+ public void start(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to start") final CloudApp appName) {
+
+ cloudFoundryOperations.start(appName.getName());
}
- // TODO: This feature was not working in the initial release JT
- // @CliCommand(value = "cloud foundry rename app", help =
- // "Delete an application")
- public void renameApp(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to rename") final CloudApp appName,
- @CliOption(key = "newAppName", mandatory = true, help = "The new name of the application") final String newAppName) {
+ @CliCommand(value = "cloud foundry stop app", help = "Stop an application")
+ public void stop(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to stop") final CloudApp appName) {
- cloudFoundryOperations.renameApp(appName.getName(), newAppName);
+ cloudFoundryOperations.stop(appName.getName());
}
- @CliCommand(value = "cloud foundry list instances", help = "List and/or change the number of application instances")
- public void instances(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to list and/or change the number instances for") final CloudApp appName,
- @CliOption(key = "num", mandatory = false, help = "The number of instances to scale the application to") final String number) {
+ @CliCommand(value = "cloud foundry unbind service", help = "Unbind a service from a deployed application")
+ public void unbindService(
+ @CliOption(key = "serviceName", mandatory = true, help = "The name of the service instance you want to bind") final CloudService service,
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application you want to bind the service to") final CloudApp appName) {
- cloudFoundryOperations.instances(appName.getName(), number);
+ cloudFoundryOperations.unbindService(service.getName(),
+ appName.getName());
}
- @CliCommand(value = "cloud foundry view app memory", help = "View or update the memory reservation for an application")
- public void viewMemory(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to view or update the reservation for") final CloudApp appName) {
+ @CliCommand(value = "cloud foundry unmap url", help = "Register an application with a URL")
+ public void unMapUrl(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to unbind the URL from") final CloudApp appName,
+ @CliOption(key = "url", mandatory = true, help = "The URL to unbind the application from") final CloudUri url) {
- cloudFoundryOperations.mem(appName.getName(), null);
+ cloudFoundryOperations.unMap(appName.getName(), url.getUri());
}
@CliCommand(value = "cloud foundry update app memory", help = "View or update the memory reservation for an application")
@@ -203,39 +255,6 @@ public void updateMemory(
cloudFoundryOperations.mem(appName.getName(), memory);
}
- @CliCommand(value = "cloud foundry view crashes", help = "View recent application crashes")
- public void crashes(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to view recent crashes for") final CloudApp appName) {
-
- cloudFoundryOperations.crashes(appName.getName());
- }
-
- @CliCommand(value = "cloud foundry view crash logs", help = "Display all the logs for crashed instance")
- public void crashLogs(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to view the crash logs for") final CloudApp appName,
- @CliOption(key = "instance", mandatory = false, help = "The name specific instance of the application of interest") final String instance) {
-
- cloudFoundryOperations.crashLogs(appName.getName(), instance);
- }
-
- @CliCommand(value = "cloud foundry view logs", help = "Display all the logs for a specific application")
- public void logs(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to view the logs for") final CloudApp appName,
- @CliOption(key = "instance", mandatory = false, help = "The name specific instance of the application of interest") final String instance) {
-
- cloudFoundryOperations.logs(appName.getName(), instance);
- }
-
- @CliCommand(value = "cloud foundry files", help = "Directory listings or file download")
- public void files(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to target") final CloudApp appName,
- @CliOption(key = "path", mandatory = true, help = "The path of the file or folder to navigate to or view") final CloudFile path,
- @CliOption(key = "instance", mandatory = false, help = "The specific instance of the application to be targeted") final String instance) {
-
- cloudFoundryOperations.files(appName.getName(), path.getFileName(),
- instance);
- }
-
@CliCommand(value = "cloud foundry view app stats", help = "Report resource usage for the application")
public void viewApptats(
@CliOption(key = "appName", mandatory = true, help = "The name of the application to target") final CloudApp appName) {
@@ -243,30 +262,10 @@ public void viewApptats(
cloudFoundryOperations.stats(appName.getName());
}
- @CliCommand(value = "cloud foundry map url", help = "Register an application with a URL")
- public void mapUrl(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to bind the URL to") final CloudApp appName,
- @CliOption(key = "url", mandatory = true, help = "The URL to bind the application to") final String url) {
-
- cloudFoundryOperations.map(appName.getName(), url);
- }
-
- @CliCommand(value = "cloud foundry unmap url", help = "Register an application with a URL")
- public void unMapUrl(
- @CliOption(key = "appName", mandatory = true, help = "The name of the application to unbind the URL from") final CloudApp appName,
- @CliOption(key = "url", mandatory = true, help = "The URL to unbind the application from") final CloudUri url) {
-
- cloudFoundryOperations.unMap(appName.getName(), url.getUri());
- }
-
- @CliCommand(value = "cloud foundry clear login details", help = "Clears all stored login information")
- public void clearStoredLoginDetails() {
- cloudFoundryOperations.clearStoredLoginDetails();
- }
+ @CliCommand(value = "cloud foundry view app memory", help = "View or update the memory reservation for an application")
+ public void viewMemory(
+ @CliOption(key = "appName", mandatory = true, help = "The name of the application to view or update the reservation for") final CloudApp appName) {
- // TODO: Add setup command once cloud namespace is more understood
- // @CliCommand(value = "cloud foundry setup", help = "Setup Cloud Foundry")
- public void config() {
- cloudFoundryOperations.setup();
+ cloudFoundryOperations.mem(appName.getName(), null);
}
}
View
82 addon-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryOperations.java
@@ -10,76 +10,76 @@
*/
public interface CloudFoundryOperations {
- void info();
-
- void register(String email, String password);
-
- void login(String email, String password, String cloudControllerUrl);
-
- void services();
-
- void createService(String service, String name, String bind);
-
- void deleteService(String service);
+ void apps();
void bindService(String service, String appName);
- void unbindService(String service, String appName);
+ void clearStoredLoginDetails();
- void apps();
+ void crashes(String appName);
- void push(String appName, Integer instances, Integer memory, String path,
- List<String> urls);
+ void crashLogs(String appName, String instance);
- void start(String appName);
+ void createService(String service, String name, String bind);
- void stop(String appName);
+ void delete(String appName);
- void restart(String appName);
+ void deleteService(String service);
- void delete(String appName);
+ void files(String appName, String path, String instance);
- void update(String appName);
+ void info();
void instances(String appName, String number);
- void mem(String appName, Integer memSize);
+ /**
+ * Check if Cloud Foundry commands are available in Shell. Depends on the
+ * user being logged into Cloud Foundry.
+ *
+ * @return availability
+ */
+ boolean isCloudFoundryCommandAvailable();
- void crashes(String appName);
+ /**
+ * Check if Cloud Foundry setup command is available in Shell.
+ *
+ * @return availability
+ */
+ boolean isSetupCommandAvailable();
- void crashLogs(String appName, String instance);
+ void login(String email, String password, String cloudControllerUrl);
void logs(String appName, String instance);
- void files(String appName, String path, String instance);
+ void map(String appName, String url);
- void stats(String appName);
+ void mem(String appName, Integer memSize);
- void map(String appName, String url);
+ void push(String appName, Integer instances, Integer memory, String path,
+ List<String> urls);
- void unMap(String appName, String url);
+ void register(String email, String password);
void renameApp(String appName, String newAppName);
- void clearStoredLoginDetails();
+ void restart(String appName);
+
+ void services();
/**
* Initial setup of Cloud Foundry in target project.
*/
void setup();
- /**
- * Check if Cloud Foundry commands are available in Shell. Depends on the
- * user being logged into Cloud Foundry.
- *
- * @return availability
- */
- boolean isCloudFoundryCommandAvailable();
+ void start(String appName);
- /**
- * Check if Cloud Foundry setup command is available in Shell.
- *
- * @return availability
- */
- boolean isSetupCommandAvailable();
+ void stats(String appName);
+
+ void stop(String appName);
+
+ void unbindService(String service, String appName);
+
+ void unMap(String appName, String url);
+
+ void update(String appName);
}
View
916 ...-cloud-foundry/src/main/java/org/springframework/roo/addon/cloud/foundry/CloudFoundryOperationsImpl.java
@@ -1,8 +1,8 @@
package org.springframework.roo.addon.cloud.foundry;
import java.io.File;
+import java.text.DateFormat;
import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@@ -41,122 +41,151 @@
public class CloudFoundryOperationsImpl extends AbstractFlashingObject
implements CloudFoundryOperations {
- // Constants
+ private abstract class CloudCommand {
+ protected boolean displaySuccessMessage = true;
+ protected String failureMessage = "";
+ protected String gerund;
+ protected String successMessage = "";
+
+ protected CloudCommand(final String failureMessage) {
+ this(failureMessage, null);
+ }
+
+ protected CloudCommand(final String failureMessage,
+ final String successMessage) {
+ this(failureMessage, successMessage, "Performing operation");
+ }
+
+ protected CloudCommand(final String failureMessage,
+ final String successMessage, final String gerund) {
+ this.failureMessage = failureMessage;
+ this.successMessage = successMessage;
+ this.gerund = gerund;
+ }
+
+ public abstract void execute() throws Exception;
+
+ public String getFailureMessage() {
+ return failureMessage;
+ }
+
+ public String getGerund() {
+ return gerund;
+ }
+
+ public String getSuccessMessage() {
+ return successMessage;
+ }
+
+ public boolean isDisplaySuccessMessage() {
+ return displaySuccessMessage;
+ }
+ }
+
private static final Logger LOGGER = HandlerUtils
.getLogger(CloudFoundryOperationsImpl.class);
+ private AppCloudClient client;
- // Fields
@Reference private CloudFoundrySession session;
- private AppCloudClient client;
- public void info() {
- executeCommand(new CloudCommand(
- "Cloud information failed to be retrieved.") {
+ public void apps() {
+ executeCommand(new CloudCommand("The applications failed to be listed.") {
@Override
public void execute() throws Exception {
- CloudInfo cloudInfo = client.getCloudInfo();
- if (cloudInfo == null || cloudInfo.getUsage() == null
- || cloudInfo.getLimits() == null) {
- LOGGER.warning("Information could not be retrieved");
+ final List<CloudApplication> applications = client
+ .getApplications();
+ if (applications.isEmpty()) {
+ LOGGER.info("No applications available.");
return;
}
- LOGGER.info("\n");
- LOGGER.info(cloudInfo.getDescription());
- LOGGER.info("For support visit " + cloudInfo.getSupport());
- LOGGER.info("\n");
- LOGGER.info("Target:\t " + client.getCloudControllerUrl()
- + " (" + cloudInfo.getVersion() + ")");
- LOGGER.info("\n");
- LOGGER.info("User:\t " + cloudInfo.getUser());
- LOGGER.info("Usage:\t Memory ("
- + cloudInfo.getUsage().getTotalMemory() + "MB of "
- + cloudInfo.getLimits().getMaxTotalMemory()
- + "MB total)");
- LOGGER.info("\t Services ("
- + cloudInfo.getUsage().getServices() + " of "
- + cloudInfo.getLimits().getMaxServices() + " total)");
- LOGGER.info("\t Apps (" + cloudInfo.getUsage().getApps()
- + " of " + cloudInfo.getLimits().getMaxApps()
- + " total)");
- LOGGER.info("\n");
+ final ShellTableRenderer table = new ShellTableRenderer(
+ "Applications", "Name", "Status", "Instances",
+ "Services", "URLs");
+ for (final CloudApplication application : applications) {
+ final StringBuilder uris = new StringBuilder();
+ for (int i = 0; i < application.getUris().size(); i++) {
+ uris.append(application.getUris().get(i));
+ if (i < (application.getUris().size() - 1)) {
+ uris.append(", ");
+ }
+ }
+ final StringBuilder services = new StringBuilder();
+ for (final String service : application.getServices()) {
+ services.append(service);
+ }
+ table.addRow(application.getName(), application.getState()
+ .name(),
+ String.valueOf(application.getInstances()),
+ services.toString(), uris.toString());
+ }
+ LOGGER.info(table.getOutput());
}
});
}
- public void register(final String email, final String password) {
- String successMessage = "Registration was successful";
- String failureMessage = "Registration failed";
+ public void bindService(final String service, final String appName) {
+ final String failureMessage = "The binding of the service '" + service
+ + "' to the application '" + appName + "' failed";
+ final String successMessage = "The service '" + service
+ + "' was successfully bound to the application '" + appName
+ + "'";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- client.register(email, password);
+ client.bindService(appName, service);
}
});
}
- public void login(final String email, final String password,
- final String cloudControllerUrl) {
- executeCommand(new CloudCommand("Login failed") {
- @Override
- public void execute() {
- session.login(email, password, cloudControllerUrl);
- client = session.getClient();
- }
- });
+ public void clearStoredLoginDetails() {
+ session.clearStoredLoginDetails();
}
- public void services() {
- executeCommand(new CloudCommand("Services could not be retrieved") {
+ public void crashes(final String appName) {
+ executeCommand(new CloudCommand("Crashes for application '" + appName
+ + "' could not be retrieved") {
@Override
public void execute() throws Exception {
- List<ServiceConfiguration> globalServices = client
- .getServiceConfigurations();
- List<CloudService> localServices = client.getServices();
- if (globalServices.isEmpty()) {
- LOGGER.info("There are currently no services available.");
- }
- else {
- ShellTableRenderer table = new ShellTableRenderer(
- "System Services", "Service", "Version",
- "Description");
- for (ServiceConfiguration service : globalServices) {
- table.addRow(service.getVendor(), service.getVersion(),
- service.getDescription());
- }
- LOGGER.info(table.getOutput());
+ final CrashesInfo crashes = client.getCrashes(appName);
+ if (crashes == null) {
+ LOGGER.severe(failureMessage);
+ return;
}
-
- if (localServices.isEmpty()) {
- LOGGER.info("There are currently no provisioned services.");
+ if (crashes.getCrashes().isEmpty()) {
+ LOGGER.info("The application '" + appName
+ + "' has never crashed");
+ return;
}
- else {
- ShellTableRenderer table = new ShellTableRenderer(
- "Provisioned Services", "Name", "Service");
-
- for (CloudService service : localServices) {
- table.addRow(service.getName(), service.getVendor());
- }
- LOGGER.info(table.getOutput());
+ final ShellTableRenderer table = new ShellTableRenderer(
+ "Crashes", "Name", "Id", "Since");
+ for (final CrashInfo crash : crashes.getCrashes()) {
+ table.addRow(appName, crash.getInstance(), DateFormat
+ .getDateTimeInstance().format(crash.getSince()));
}
+ LOGGER.info(table.getOutput());
}
});
}
+ public void crashLogs(final String appName, final String instance) {
+ logs(appName, instance);
+ }
+
public void createService(final String service, final String name,
final String bind) {
- String failureMessage = "The service '" + name
+ final String failureMessage = "The service '" + name
+ "' failed to be created";
- String successMessage = "The service '" + name
+ final String successMessage = "The service '" + name
+ "' was successfully created";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- CloudService cloudService = new CloudService();
+ final CloudService cloudService = new CloudService();
cloudService.setName(name);
cloudService.setTier("free");
- List<ServiceConfiguration> serviceConfigurations = client
+ final List<ServiceConfiguration> serviceConfigurations = client
.getServiceConfigurations();
- for (ServiceConfiguration serviceConfiguration : serviceConfigurations) {
+ for (final ServiceConfiguration serviceConfiguration : serviceConfigurations) {
if (serviceConfiguration.getVendor().equals(service)) {
cloudService
.setVendor(serviceConfiguration.getVendor());
@@ -170,10 +199,23 @@ public void execute() throws Exception {
});
}
+ public void delete(final String appName) {
+ final String failureMessage = "The application '" + appName
+ + "' could not be deleted";
+ final String successMessage = "The application '" + appName
+ + "' was successfully deleted";
+ executeCommand(new CloudCommand(failureMessage, successMessage) {
+ @Override
+ public void execute() throws Exception {
+ client.deleteApplication(appName);
+ }
+ });
+ }
+
public void deleteService(final String service) {
- String failureMessage = "The service '" + service
+ final String failureMessage = "The service '" + service
+ "' failed to be deleted";
- String successMessage = "The service '" + service
+ final String successMessage = "The service '" + service
+ "' was deleted successfully";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
@@ -183,64 +225,243 @@ public void execute() throws Exception {
});
}
- public void bindService(final String service, final String appName) {
- String failureMessage = "The binding of the service '" + service
- + "' to the application '" + appName + "' failed";
- String successMessage = "The service '" + service
- + "' was successfully bound to the application '" + appName
- + "'";
- executeCommand(new CloudCommand(failureMessage, successMessage) {
+ private void executeCommand(final CloudCommand command) {
+ final Timer timer = new Timer();
+ try {
+ final char[] statusIndicators = new char[] { '|', '/', '-', '\\' };
+ final int[] statusCount = new int[] { 0 };
+ final TimerTask timerTask = new TimerTask() {
+ @Override
+ public void run() {
+ flash(Level.FINE, command.getGerund() + " "
+ + statusIndicators[statusCount[0]], MY_SLOT);
+ if (statusCount[0] < (statusIndicators.length - 1)) {
+ statusCount[0] = statusCount[0] + 1;
+ }
+ else {
+ statusCount[0] = 0;
+ }
+ }
+ };
+ timer.scheduleAtFixedRate(timerTask, 0, 100);
+ command.execute();
+ if (StringUtils.hasText(command.getSuccessMessage())
+ && command.isDisplaySuccessMessage()) {
+ LOGGER.info(command.getSuccessMessage());
+ }
+ }
+ catch (final Exception e) {
+ throw new IllegalStateException(command.getFailureMessage() + " - "
+ + e.getMessage(), e);
+ }
+ finally {
+ timer.cancel();
+ flash(Level.FINE, "Complete!", MY_SLOT);
+ flash(Level.FINE, "", MY_SLOT);
+ }
+ }
+
+ public void files(final String appName, final String path,
+ final String instance) {
+ executeCommand(new CloudCommand("The files failed to be retrieved") {
@Override
public void execute() throws Exception {
- client.bindService(appName, service);
+ Integer instanceIndex = getInteger(instance);
+ if (instanceIndex == null) {
+ instanceIndex = 1;
+ }
+ final String file = client
+ .getFile(appName, instanceIndex, path);
+ LOGGER.info(file);
}
});
}
- public void unbindService(final String service, final String appName) {
- String failureMessage = "The unbinding of the service '" + service
- + "' from the application '" + appName + "' failed";
- String successMessage = "The service '" + service
- + "' was successfully unbound from the application '" + appName
- + "'";
- executeCommand(new CloudCommand(failureMessage, successMessage) {
+ private String formatDurationInSeconds(final Double seconds) {
+ final long secondsInMinute = 60;
+ final long secondsInHour = secondsInMinute ^ 2;
+ final long secondsInDay = secondsInHour * 24;
+ final StringBuilder sb = new StringBuilder();
+ final long days = (long) (seconds / secondsInDay);
+ sb.append(days).append("d:");
+ if (days > 1) {
+ double remainder = seconds % secondsInDay;
+ final long hours = (long) ((remainder) / (secondsInHour));
+ sb.append(hours).append("h:");
+
+ remainder = remainder % (secondsInHour);
+ final long minutes = (long) (remainder / (60));
+ sb.append(minutes).append("m:");
+
+ remainder = remainder % (60);
+ final long secs = (long) (remainder);
+ sb.append(secs).append("s");
+ }
+ return sb.toString();
+ }
+
+ private CloudApplication getApplication(final String appName) {
+ try {
+ return client.getApplication(appName);
+ }
+ catch (final Exception ignored) {
+ }
+ return null;
+ }
+
+ private Integer getInteger(final String potentialInt) {
+ if (potentialInt == null) {
+ return null;
+ }
+ for (final Character c : potentialInt.toCharArray()) {
+ if (!Character.isDigit(c)) {
+ return null;
+ }
+ }
+ return Integer.valueOf(potentialInt);
+ }
+
+ public void info() {
+ executeCommand(new CloudCommand(
+ "Cloud information failed to be retrieved.") {
@Override
public void execute() throws Exception {
- client.unbindService(appName, service);
+ final CloudInfo cloudInfo = client.getCloudInfo();
+ if ((cloudInfo == null) || (cloudInfo.getUsage() == null)
+ || (cloudInfo.getLimits() == null)) {
+ LOGGER.warning("Information could not be retrieved");
+ return;
+ }
+ LOGGER.info("\n");
+ LOGGER.info(cloudInfo.getDescription());
+ LOGGER.info("For support visit " + cloudInfo.getSupport());
+ LOGGER.info("\n");
+ LOGGER.info("Target:\t " + client.getCloudControllerUrl()
+ + " (" + cloudInfo.getVersion() + ")");
+ LOGGER.info("\n");
+ LOGGER.info("User:\t " + cloudInfo.getUser());
+ LOGGER.info("Usage:\t Memory ("
+ + cloudInfo.getUsage().getTotalMemory() + "MB of "
+ + cloudInfo.getLimits().getMaxTotalMemory()
+ + "MB total)");
+ LOGGER.info("\t Services ("
+ + cloudInfo.getUsage().getServices() + " of "
+ + cloudInfo.getLimits().getMaxServices() + " total)");
+ LOGGER.info("\t Apps (" + cloudInfo.getUsage().getApps()
+ + " of " + cloudInfo.getLimits().getMaxApps()
+ + " total)");
+ LOGGER.info("\n");
}
});
}
- public void apps() {
- executeCommand(new CloudCommand("The applications failed to be listed.") {
+ public void instances(final String appName, final String number) {
+ executeCommand(new CloudCommand(
+ "Retrieving instances for application '" + appName + "' failed") {
@Override
public void execute() throws Exception {
- List<CloudApplication> applications = client.getApplications();
- if (applications.isEmpty()) {
- LOGGER.info("No applications available.");
+ final Integer instances = getInteger(number);
+ if (instances == null) {
+ final InstancesInfo instancesInfo = client
+ .getApplicationInstances(appName);
+ if (instancesInfo.getInstances().isEmpty()) {
+ LOGGER.info("No running instances for '" + appName
+ + "'");
+ }
+ }
+ else {
+ client.updateApplicationInstances(appName, instances);
+ }
+ }
+ });
+ }
+
+ public boolean isCloudFoundryCommandAvailable() {
+ return client != null;
+ }
+
+ public boolean isSetupCommandAvailable() {
+ return true;
+ }
+
+ public void login(final String email, final String password,
+ final String cloudControllerUrl) {
+ executeCommand(new CloudCommand("Login failed") {
+ @Override
+ public void execute() {
+ session.login(email, password, cloudControllerUrl);
+ client = session.getClient();
+ }
+ });
+ }
+
+ public void logs(final String appName, final String instance) {
+ final String failureMessage = "The logs for application '" + appName
+ + "' failed to be retrieved";
+ final String successMessage = null;
+ executeCommand(new CloudCommand(failureMessage, successMessage,
+ "Loading") {
+ @Override
+ public void execute() throws Exception {
+ Integer instanceIndex = getInteger(instance);
+ if (instanceIndex == null) {
+ instanceIndex = 1;
+ }
+
+ final String stderrLog = client.getFile(appName, instanceIndex,
+ "logs/stderr.log");
+ final String stdoutlog = client.getFile(appName, instanceIndex,
+ "logs/stdout.log");
+
+ LOGGER.info("\n");
+ LOGGER.info("==== logs/stderr.log ====");
+ LOGGER.info("\n");
+ LOGGER.info(stderrLog);
+
+ LOGGER.info("\n");
+ LOGGER.info("==== logs/stdout.log ====");
+ LOGGER.info("\n");
+ LOGGER.info(stdoutlog);
+ LOGGER.info("\n");
+ }
+ });
+ }
+
+ public void map(final String appName, final String url) {
+ final String failureMessage = "The url failed to be mapped to application '"
+ + appName + "'";
+ final String successMessage = "The url was successfully mapped to application '"
+ + appName + "'";
+ executeCommand(new CloudCommand(failureMessage, successMessage) {
+ @Override
+ public void execute() throws Exception {
+ final CloudApplication application = getApplication(appName);
+ if (application == null) {
+ displaySuccessMessage = false;
return;
}
- ShellTableRenderer table = new ShellTableRenderer(
- "Applications", "Name", "Status", "Instances",
- "Services", "URLs");
- for (CloudApplication application : applications) {
- StringBuilder uris = new StringBuilder();
- for (int i = 0; i < application.getUris().size(); i++) {
- uris.append(application.getUris().get(i));
- if (i < application.getUris().size() - 1) {
- uris.append(", ");
- }
- }
- StringBuilder services = new StringBuilder();
- for (String service : application.getServices()) {
- services.append(service);
- }
- table.addRow(application.getName(), application.getState()
- .name(),
- String.valueOf(application.getInstances()),
- services.toString(), uris.toString());
+ final List<String> uris = new ArrayList<String>(
+ application.getUris());
+ uris.add(url);
+ client.updateApplicationUris(appName, uris);
+ }
+ });
+ }
+
+ public void mem(final String appName, final Integer memSize) {
+ executeCommand(new CloudCommand(
+ "Updating the memory allocation for application '" + appName
+ + "' failed") {
+ @Override
+ public void execute() throws Exception {
+ if (memSize != null) {
+ client.updateApplicationMemory(appName, memSize);
}
- LOGGER.info(table.getOutput());
+ final ShellTableRenderer shellTable = new ShellTableRenderer(
+ "Application Memory", "Name", "Memory");
+ shellTable.addRow(appName, getApplication(appName).getMemory()
+ + "MB");
+ LOGGER.info(shellTable.getOutput());
}
});
}
@@ -251,7 +472,7 @@ public void push(final String appName, final Integer instances,
LOGGER.severe("The file path cannot be null; cannot continue");
return;
}
- File fileToDeploy = new File(path);
+ final File fileToDeploy = new File(path);
if (!fileToDeploy.exists()) {
LOGGER.severe("The file at path '" + path
+ "' doesn't exist; cannot continue");
@@ -260,16 +481,16 @@ public void push(final String appName, final Integer instances,
if (memory == null) {
memory = 256;
}
- String failureMessage = "The application '" + appName
+ final String failureMessage = "The application '" + appName
+ "' could not be pushed";
- String successMessage = "The application '" + appName
+ final String successMessage = "The application '" + appName
+ "' was successfully pushed";
final Integer finalMem = memory;
executeCommand(new CloudCommand(failureMessage, successMessage,
"Uploading") {
@Override
public void execute() throws Exception {
- CloudApplication cloudApplication = getApplication(appName);
+ final CloudApplication cloudApplication = getApplication(appName);
List<String> finalUrls = urls;
if (finalUrls == null) {
finalUrls = new ArrayList<String>();
@@ -292,186 +513,114 @@ public void execute() throws Exception {
});
}
- public void start(final String appName) {
- String failureMessage = "The application '" + appName
- + "' could not be started";
- String successMessage = "The application '" + appName
- + "' was successfully started";
- executeCommand(new CloudCommand(failureMessage, successMessage,
- "Starting") {
- @Override
- public void execute() throws Exception {
- if (getApplication(appName).getState() == CloudApplication.AppState.STARTED) {
- LOGGER.info("Application '" + appName
- + "' is already running.");
- displaySuccessMessage = false;
- return;
- }
- client.startApplication(appName);
- }
- });
- }
-
- public void stop(final String appName) {
- String failureMessage = "The application '" + appName
- + "' could not be stopped";
- String successMessage = "The application '" + appName
- + "' was successfully stopped";
- executeCommand(new CloudCommand(failureMessage, successMessage, appName) {
- @Override
- public void execute() throws Exception {
- if (getApplication(appName).getState() == CloudApplication.AppState.STOPPED) {
- LOGGER.info("Application '" + appName + "' is not running.");
- displaySuccessMessage = false;
- return;
- }
- client.stopApplication(appName);
- }
- });
- }
-
- public void restart(final String appName) {
- String failureMessage = "The application '" + appName
- + "' could not be restarted";
- String successMessage = "The application '" + appName
- + "' was successfully restarted";
+ public void register(final String email, final String password) {
+ final String successMessage = "Registration was successful";
+ final String failureMessage = "Registration failed";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- client.restartApplication(appName);
+ client.register(email, password);
}
});
}
- public void delete(final String appName) {
- String failureMessage = "The application '" + appName
- + "' could not be deleted";
- String successMessage = "The application '" + appName
- + "' was successfully deleted";
+ public void renameApp(final String appName, final String newAppName) {
+ final String failureMessage = "The application '" + appName
+ + "'failed to be renamed";
+ final String successMessage = "The application '" + appName
+ + "' was successfully renamed as '" + newAppName + "'";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- client.deleteApplication(appName);
- }
- });
- }
-
- public void update(final String appName) {
-
- }
-
- public void instances(final String appName, final String number) {
- executeCommand(new CloudCommand(
- "Retrieving instances for application '" + appName + "' failed") {
- @Override
- public void execute() throws Exception {
- Integer instances = getInteger(number);
- if (instances == null) {
- InstancesInfo instancesInfo = client
- .getApplicationInstances(appName);
- if (instancesInfo.getInstances().isEmpty()) {
- LOGGER.info("No running instances for '" + appName
- + "'");
+ for (final CloudApplication cloudApplication : client
+ .getApplications()) {
+ if (cloudApplication.getName().equals(newAppName)) {
+ LOGGER.severe("An application of that name already exists, please choose another name");
+ displaySuccessMessage = false;
+ return;
}
}
- else {
- client.updateApplicationInstances(appName, instances);
- }
- }
- });
- }
-
- public void mem(final String appName, final Integer memSize) {
- executeCommand(new CloudCommand(
- "Updating the memory allocation for application '" + appName
- + "' failed") {
- @Override
- public void execute() throws Exception {
- if (memSize != null) {
- client.updateApplicationMemory(appName, memSize);
- }
- ShellTableRenderer shellTable = new ShellTableRenderer(
- "Application Memory", "Name", "Memory");
- shellTable.addRow(appName, getApplication(appName).getMemory()
- + "MB");
- LOGGER.info(shellTable.getOutput());
+ client.rename(appName, newAppName);
}
});
- }
-
- public void crashes(final String appName) {
- executeCommand(new CloudCommand("Crashes for application '" + appName
- + "' could not be retrieved") {
+ }
+
+ public void restart(final String appName) {
+ final String failureMessage = "The application '" + appName
+ + "' could not be restarted";
+ final String successMessage = "The application '" + appName
+ + "' was successfully restarted";
+ executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- CrashesInfo crashes = client.getCrashes(appName);
- if (crashes == null) {
- LOGGER.severe(this.failureMessage);
- return;
- }
- if (crashes.getCrashes().isEmpty()) {
- LOGGER.info("The application '" + appName
- + "' has never crashed");
- return;
- }
- ShellTableRenderer table = new ShellTableRenderer("Crashes",
- "Name", "Id", "Since");
- for (CrashInfo crash : crashes.getCrashes()) {
- table.addRow(appName, crash.getInstance(), SimpleDateFormat
- .getDateTimeInstance().format(crash.getSince()));
- }
- LOGGER.info(table.getOutput());
+ client.restartApplication(appName);
}
});
}
- public void crashLogs(final String appName, final String instance) {
- logs(appName, instance);
+ private double roundTwoDecimals(final double d) {
+ final DecimalFormat twoDForm = new DecimalFormat("#.##");
+ return Double.valueOf(twoDForm.format(d));
}
- public void logs(final String appName, final String instance) {
- String failureMessage = "The logs for application '" + appName
- + "' failed to be retrieved";
- String successMessage = null;
- executeCommand(new CloudCommand(failureMessage, successMessage,
- "Loading") {
+ public void services() {
+ executeCommand(new CloudCommand("Services could not be retrieved") {
@Override
public void execute() throws Exception {
- Integer instanceIndex = getInteger(instance);
- if (instanceIndex == null) {
- instanceIndex = 1;
+ final List<ServiceConfiguration> globalServices = client
+ .getServiceConfigurations();
+ final List<CloudService> localServices = client.getServices();
+ if (globalServices.isEmpty()) {
+ LOGGER.info("There are currently no services available.");
+ }
+ else {
+ final ShellTableRenderer table = new ShellTableRenderer(
+ "System Services", "Service", "Version",
+ "Description");
+ for (final ServiceConfiguration service : globalServices) {
+ table.addRow(service.getVendor(), service.getVersion(),
+ service.getDescription());
+ }
+ LOGGER.info(table.getOutput());
}
- String stderrLog = client.getFile(appName, instanceIndex,
- "logs/stderr.log");
- String stdoutlog = client.getFile(appName, instanceIndex,
- "logs/stdout.log");
-
- LOGGER.info("\n");
- LOGGER.info("==== logs/stderr.log ====");
- LOGGER.info("\n");
- LOGGER.info(stderrLog);
+ if (localServices.isEmpty()) {
+ LOGGER.info("There are currently no provisioned services.");
+ }
+ else {
+ final ShellTableRenderer table = new ShellTableRenderer(
+ "Provisioned Services", "Name", "Service");
- LOGGER.info("\n");
- LOGGER.info("==== logs/stdout.log ====");
- LOGGER.info("\n");
- LOGGER.info(stdoutlog);
- LOGGER.info("\n");
+ for (final CloudService service : localServices) {
+ table.addRow(service.getName(), service.getVendor());
+ }
+ LOGGER.info(table.getOutput());
+ }
}
});
}
- public void files(final String appName, final String path,
- final String instance) {
- executeCommand(new CloudCommand("The files failed to be retrieved") {
+ public void setup() {
+ // TODO: This is where a cloud environment profile would be added to the
+ // application config
+ }
+
+ public void start(final String appName) {
+ final String failureMessage = "The application '" + appName
+ + "' could not be started";
+ final String successMessage = "The application '" + appName
+ + "' was successfully started";
+ executeCommand(new CloudCommand(failureMessage, successMessage,
+ "Starting") {
@Override
public void execute() throws Exception {
- Integer instanceIndex = getInteger(instance);
- if (instanceIndex == null) {
- instanceIndex = 1;
+ if (getApplication(appName).getState() == CloudApplication.AppState.STARTED) {
+ LOGGER.info("Application '" + appName
+ + "' is already running.");
+ displaySuccessMessage = false;
+ return;
}
- String file = client.getFile(appName, instanceIndex, path);
- LOGGER.info(file);
+ client.startApplication(appName);
}
});
}
@@ -481,18 +630,19 @@ public void stats(final String appName) {
+ "' failed to be retrieved") {
@Override
public void execute() throws Exception {
- ApplicationStats stats = client.getApplicationStats(appName);
+ final ApplicationStats stats = client
+ .getApplicationStats(appName);
if (stats.getRecords().isEmpty()) {
LOGGER.info("There is currently no stats for the application '"
+ appName + "'");
return;
}
- ShellTableRenderer table = new ShellTableRenderer("App. Stats",
- "Instance", "CPU (Cores)", "Memory (limit)",
- "Disk (limit)", "Uptime");
- for (InstanceStats instanceStats : stats.getRecords()) {
- String instance = instanceStats.getId();
- InstanceStats.Usage usage = instanceStats.getUsage();
+ final ShellTableRenderer table = new ShellTableRenderer(
+ "App. Stats", "Instance", "CPU (Cores)",
+ "Memory (limit)", "Disk (limit)", "Uptime");
+ for (final InstanceStats instanceStats : stats.getRecords()) {
+ final String instance = instanceStats.getId();
+ final InstanceStats.Usage usage = instanceStats.getUsage();
String cpu = "N/A";
String memory = "N/A";
String disk = "N/A";
@@ -502,20 +652,19 @@ public void execute() throws Exception {
memory = roundTwoDecimals(instanceStats.getUsage()
.getMem() / 1024)
+ "M ("
- + instanceStats.getMemQuota()
- / (1024 * 1024)
+ + (instanceStats.getMemQuota() / (1024 * 1024))
+ "M)";
disk = roundTwoDecimals(instanceStats.getUsage()
.getDisk() / (1024 * 1024))
+ "M ("
- + instanceStats.getDiskQuota()
- / (1024 * 1024) + "M)";
+ + (instanceStats.getDiskQuota() / (1024 * 1024))
+ + "M)";
}
Double uptime = instanceStats.getUptime();
if (uptime == null) {
uptime = 0D;
}
- String formattedUptime = formatDurationInSeconds(uptime);
+ final String formattedUptime = formatDurationInSeconds(uptime);
table.addRow(instance, cpu, memory, disk, formattedUptime);
}
LOGGER.info(table.getOutput());
@@ -523,207 +672,60 @@ public void execute() throws Exception {
});
}
- public void map(final String appName, final String url) {
- String failureMessage = "The url failed to be mapped to application '"
- + appName + "'";
- String successMessage = "The url was successfully mapped to application '"
- + appName + "'";
- executeCommand(new CloudCommand(failureMessage, successMessage) {
+ public void stop(final String appName) {
+ final String failureMessage = "The application '" + appName
+ + "' could not be stopped";
+ final String successMessage = "The application '" + appName
+ + "' was successfully stopped";
+ executeCommand(new CloudCommand(failureMessage, successMessage, appName) {
@Override
public void execute() throws Exception {
- CloudApplication application = getApplication(appName);
- if (application == null) {
+ if (getApplication(appName).getState() == CloudApplication.AppState.STOPPED) {
+ LOGGER.info("Application '" + appName + "' is not running.");
displaySuccessMessage = false;
return;
}
- List<String> uris = new ArrayList<String>(application.getUris());
- uris.add(url);
- client.updateApplicationUris(appName, uris);
+ client.stopApplication(appName);
+ }
+ });
+ }
+
+ public void unbindService(final String service, final String appName) {
+ final String failureMessage = "The unbinding of the service '"
+ + service + "' from the application '" + appName + "' failed";
+ final String successMessage = "The service '" + service
+ + "' was successfully unbound from the application '" + appName
+ + "'";
+ executeCommand(new CloudCommand(failureMessage, successMessage) {
+ @Override
+ public void execute() throws Exception {
+ client.unbindService(appName, service);
}
});
}
public void unMap(final String appName, final String url) {
- String failureMessage = "The url failed to be unmapped from application '"
+ final String failureMessage = "The url failed to be unmapped from application '"
+ appName + "'";
- String successMessage = "The url was successfully unmapped from application '"
+ final String successMessage = "The url was successfully unmapped from application '"
+ appName + "'";
executeCommand(new CloudCommand(failureMessage, successMessage) {
@Override
public void execute() throws Exception {
- CloudApplication application = getApplication(appName);
+ final CloudApplication application = getApplication(appName);
if (application == null) {
displaySuccessMessage = false;
return;
}
- List<String> uris = new ArrayList<String>(application.getUris());
+ final List<String> uris = new ArrayList<String>(
+ application.getUris());
uris.remove(url);
client.updateApplicationUris(appName, uris);
}
});
}