provisionr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject git commit: PROVISIONR-41. Fix Sonar violations (part 2)
Date Wed, 10 Jul 2013 09:45:36 GMT
Updated Branches:
  refs/heads/master 3f00190a6 -> d8504b886


PROVISIONR-41. Fix Sonar violations (part 2)


Project: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/commit/d8504b88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/tree/d8504b88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/diff/d8504b88

Branch: refs/heads/master
Commit: d8504b886903d2dea6af5d9500d31d05c0dc4131
Parents: 3f00190
Author: Andrei Savu <asavu@apache.org>
Authored: Wed Jul 10 12:38:00 2013 +0300
Committer: Andrei Savu <asavu@apache.org>
Committed: Wed Jul 10 12:38:00 2013 +0300

----------------------------------------------------------------------
 .../activiti/karaf/commands/AddUserCommand.java | 11 ++++----
 .../karaf/commands/ListActivitiCommand.java     |  2 +-
 .../core/activities/PuppetActivity.java         |  3 ++-
 .../provisionr/commands/CreateCommand.java      | 28 +++++++++++++++-----
 .../provisionr/commands/CreateImageCommand.java | 14 ++++------
 .../provisionr/commands/CreatePoolCommand.java  |  6 ++---
 .../commands/ResetRetriesCommand.java           |  6 ++---
 .../resources/OSGI-INF/blueprint/context.xml    |  8 ++++++
 .../provisionr/cloudstack/ProcessVariables.java |  2 +-
 .../cloudstack/core/VirtualMachines.java        |  3 ++-
 10 files changed, 53 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/AddUserCommand.java
----------------------------------------------------------------------
diff --git a/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/AddUserCommand.java
b/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/AddUserCommand.java
index 98b1069..951f06a 100644
--- a/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/AddUserCommand.java
+++ b/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/AddUserCommand.java
@@ -18,6 +18,7 @@
 
 package org.apache.provisionr.activiti.karaf.commands;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.activiti.engine.IdentityService;
 import org.activiti.engine.identity.User;
 import org.apache.felix.gogo.commands.Command;
@@ -40,15 +41,15 @@ public class AddUserCommand extends ActivitiCommand {
 
     @Override
     protected Object doExecute() {
-        if (getProcessEngine() == null) {
-            throw new NullPointerException("Please configure a processEngine instance for
this command");
-        }
+        checkNotNull(getProcessEngine(), "No process engine found");
+
         IdentityService identityService = getProcessEngine().getIdentityService();
 
         User user = identityService.newUser(id);
-        user.setEmail(password);
-        identityService.saveUser(user);
+        user.setEmail(email);
+        user.setPassword(password);
 
+        identityService.saveUser(user);
         identityService.createMembership(id, groupId);
 
         return null;

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/ListActivitiCommand.java
----------------------------------------------------------------------
diff --git a/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/ListActivitiCommand.java
b/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/ListActivitiCommand.java
index ee149ae..2ea7f1e 100644
--- a/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/ListActivitiCommand.java
+++ b/activiti/commands/src/main/java/org/apache/provisionr/activiti/karaf/commands/ListActivitiCommand.java
@@ -54,7 +54,7 @@ public class ListActivitiCommand extends ActivitiCommand {
 
 
     @Override
-    protected Object doExecute() throws Exception {
+    protected Object doExecute() {
         ProcessEngine pe = this.getProcessEngine();
 
         if (pe == null) {

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/core/src/main/java/org/apache/provisionr/core/activities/PuppetActivity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/provisionr/core/activities/PuppetActivity.java
b/core/src/main/java/org/apache/provisionr/core/activities/PuppetActivity.java
index c6a8bad..47b99e6 100644
--- a/core/src/main/java/org/apache/provisionr/core/activities/PuppetActivity.java
+++ b/core/src/main/java/org/apache/provisionr/core/activities/PuppetActivity.java
@@ -20,6 +20,7 @@ package org.apache.provisionr.core.activities;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
 import java.util.Map;
 import net.schmizz.sshj.SSHClient;
 import net.schmizz.sshj.connection.channel.direct.Session;
@@ -79,7 +80,7 @@ public abstract class PuppetActivity implements JavaDelegate {
     }
 
     @Override
-    public void execute(DelegateExecution execution) throws Exception {
+    public void execute(DelegateExecution execution) throws IOException {
         Pool pool = (Pool) execution.getVariable(CoreProcessVariables.POOL);
         checkNotNull(pool, "Please add the pool description as a process " +
             "variable with the name '%s'.", CoreProcessVariables.POOL);

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java
----------------------------------------------------------------------
diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java
b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java
index 1696c2c..6e366e8 100644
--- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java
+++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java
@@ -47,18 +47,18 @@ import org.apache.provisionr.core.templates.PoolTemplate;
 public abstract class CreateCommand extends OsgiCommandSupport {
 
     @Option(name = "--id", description = "Service ID (use provisionr:services)", required
= true)
-    protected String id;
+    private String id;
 
     @Option(name = "--package", description = "Package to install by default (multi-valued)",
         multiValued = true)
-    protected List<String> packages = Lists.newArrayList();
+    private List<String> packages = Lists.newArrayList();
 
     @Option(name = "-t", aliases = "--template", description = "Pre-configured template (packages,
files)")
-    protected String template;
+    private String template;
 
     @Option(name = "--timeout", description = "Timeout in seconds for the command's initialization
steps. " +
         "If not specified, defaults to 600 seconds.")
-    protected int bootstrapTimeout = 600;
+    private int bootstrapTimeout = 600;
 
     @Option(name = "--public-key-path", description = "Path to the public key. " +
         "The default value can be overridden in org.apache.provisionr.core")
@@ -68,9 +68,9 @@ public abstract class CreateCommand extends OsgiCommandSupport {
         "The default value can be overridden in org.apache.provisionr.core")
     private String privateKeyPath;
 
-    protected final List<Provisionr> services;
+    private final List<Provisionr> services;
 
-    protected final List<PoolTemplate> templates;
+    private final List<PoolTemplate> templates;
 
     public CreateCommand(List<Provisionr> services, List<PoolTemplate> templates,
                          String publicKeyPath, String privateKeyPath) {
@@ -81,6 +81,22 @@ public abstract class CreateCommand extends OsgiCommandSupport {
         this.privateKeyPath = checkNotNull(privateKeyPath, "privateKeyPath is null");
     }
 
+    public String getId() {
+        return id;
+    }
+
+    public List<String> getPackages() {
+        return packages;
+    }
+
+    public String getTemplate() {
+        return template;
+    }
+
+    public int getBootstrapTimeout() {
+        return bootstrapTimeout;
+    }
+
     @VisibleForTesting
     void setId(String id) {
         this.id = checkNotNull(id, "id is null");

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java
----------------------------------------------------------------------
diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java
b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java
index 74c6e81..46a2555 100644
--- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java
+++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java
@@ -40,18 +40,14 @@ public class CreateImageCommand extends CreateCommand {
     }
 
     @Override
-    protected Object doExecute() throws Exception {
-        // Provisionr service = getService();
-        // final Pool pool = createPoolOfOne(service);
-        // TODO: create service.startCachingProcess(uuid, pool) in the Provisionr class
-
-        return null;
+    protected Object doExecute() {
+        return "Not implemented.";
     }
 
     @VisibleForTesting
     Pool createPoolOfOne(Provisionr service) {
 
-        final Software software = Software.builder().packages(packages).createSoftware();
+        final Software software = Software.builder().packages(getPackages()).createSoftware();
         final Hardware hardware = Hardware.builder().type(HARDWARE_TYPE).createHardware();
 
         final Pool pool = Pool.builder()
@@ -62,10 +58,10 @@ public class CreateImageCommand extends CreateCommand {
             .adminAccess(collectCurrentUserCredentialsForAdminAccess())
             .minSize(1)
             .expectedSize(1)
-            .bootstrapTimeInSeconds(bootstrapTimeout)
+            .bootstrapTimeInSeconds(getBootstrapTimeout())
             .createPool();
 
-        return template != null ? applyTemplate(pool) : pool;
+        return getTemplate() != null ? applyTemplate(pool) : pool;
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java
----------------------------------------------------------------------
diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java
b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java
index 4091066..e99249f 100644
--- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java
+++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java
@@ -103,7 +103,7 @@ public class CreatePoolCommand extends CreateCommand {
         Provider provider = defaultProvider.get().toBuilder().options(options).createProvider();
 
         final Software software = Software.builder()
-            .packages(packages)
+            .packages(getPackages())
             .imageId(imageId)
             .cachedImage(cachedImage)
             .createSoftware();
@@ -121,10 +121,10 @@ public class CreatePoolCommand extends CreateCommand {
             .adminAccess(collectCurrentUserCredentialsForAdminAccess())
             .minSize(size)
             .expectedSize(size)
-            .bootstrapTimeInSeconds(bootstrapTimeout)
+            .bootstrapTimeInSeconds(getBootstrapTimeout())
             .createPool();
 
-        return template != null ? applyTemplate(pool) : pool;
+        return getTemplate() != null ? applyTemplate(pool) : pool;
     }
 
     private List<BlockDevice> parseBlockDeviceOptions(List<String> options) {

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/karaf/commands/src/main/java/org/apache/provisionr/commands/ResetRetriesCommand.java
----------------------------------------------------------------------
diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/ResetRetriesCommand.java
b/karaf/commands/src/main/java/org/apache/provisionr/commands/ResetRetriesCommand.java
index 88f4bbf..6605181 100644
--- a/karaf/commands/src/main/java/org/apache/provisionr/commands/ResetRetriesCommand.java
+++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/ResetRetriesCommand.java
@@ -47,7 +47,7 @@ public class ResetRetriesCommand extends OsgiCommandSupport {
     }
 
     @Override
-    protected Object doExecute() throws Exception {
+    protected Object doExecute() {
         if (businessKey == null || businessKey.isEmpty()) {
             out.println("Please supply a business key");
         } else {
@@ -56,7 +56,7 @@ public class ResetRetriesCommand extends OsgiCommandSupport {
                 .createProcessInstanceQuery().variableValueEquals(CoreProcessVariables.POOL_BUSINESS_KEY,
businessKey)
                 .orderByProcessInstanceId().desc().list();
 
-            out.printf("Found %d processes with pool business key %s\n", processInstanceList.size(),
businessKey);
+            out.printf("Found %d processes with pool business key %s%n", processInstanceList.size(),
businessKey);
             int count = 0;
             for (ProcessInstance instance : processInstanceList) {
                 List<Job> jobs = processEngine.getManagementService().createJobQuery()
@@ -66,7 +66,7 @@ public class ResetRetriesCommand extends OsgiCommandSupport {
                     processEngine.getManagementService().setJobRetries(job.getId(), JobEntity.DEFAULT_RETRIES);
                 }
             }
-            out.printf("Number of retries reset for %s jobs\n", count);
+            out.printf("Number of retries reset for %s jobs%n", count);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml
----------------------------------------------------------------------
diff --git a/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml b/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml
index 53d7375..54f965e 100644
--- a/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml
+++ b/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml
@@ -64,6 +64,14 @@
                 <shell:argument value="${privateKeyPath}"/>
             </shell:action>
         </shell:command>
+        <shell:command name="provisionr/create-image">
+            <shell:action class="org.apache.provisionr.commands.CreateImageCommand">
+                <shell:argument ref="provisionrServices"/>
+                <shell:argument ref="templates"/>
+                <shell:argument value="${publicKeyPath}"/>
+                <shell:argument value="${privateKeyPath}"/>
+            </shell:action>
+        </shell:command>
         <shell:command name="provisionr/destroy">
             <shell:action class="org.apache.provisionr.commands.DestroyPoolCommand">
                 <shell:argument ref="provisionrServices"/>

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
index 421359f..7365a75 100644
--- a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/ProcessVariables.java
@@ -18,7 +18,7 @@
 
 package org.apache.provisionr.cloudstack;
 
-public class ProcessVariables {
+public final class ProcessVariables {
 
     private ProcessVariables() {
         // prevent instantiation

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/d8504b88/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/core/VirtualMachines.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/core/VirtualMachines.java
b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/core/VirtualMachines.java
index e31ca68..bcd83ff 100644
--- a/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/core/VirtualMachines.java
+++ b/providers/cloudstack/src/main/java/org/apache/provisionr/cloudstack/core/VirtualMachines.java
@@ -38,7 +38,8 @@ import org.slf4j.LoggerFactory;
 public class VirtualMachines {
 
     private static final Logger LOG = LoggerFactory.getLogger(VirtualMachines.class);
-    public static int WAIT_TIME_OUT_IN_SECONDS = 180;
+
+    public static final int WAIT_TIME_OUT_IN_SECONDS = 180;
     public static final int BETWEEN_REQUESTS_SLEEP_TIME = WAIT_TIME_OUT_IN_SECONDS / 10;
 
     private VirtualMachines() {


Mime
View raw message