Skip to content

Commit

Permalink
JCloudSlave now inherit from AbstractCloudSlave instead of Slave
Browse files Browse the repository at this point in the history
  • Loading branch information
mavlyutov committed Jan 28, 2014
1 parent bd11bb8 commit 54258e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package jenkins.plugins.jclouds.compute;

import hudson.model.Hudson;
import hudson.model.Slave;
import hudson.slaves.AbstractCloudComputer;
import hudson.slaves.OfflineCause;
import hudson.slaves.SlaveComputer;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;

import java.io.IOException;
import java.util.logging.Logger;

import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;

/**
* JClouds version of Jenkins {@link SlaveComputer} - responsible for terminating an instance.
*
* @author Vijay Kiran
*/
public class JCloudsComputer extends SlaveComputer {
public class JCloudsComputer extends AbstractCloudComputer<JCloudsSlave> {

private static final Logger LOGGER = Logger.getLogger(JCloudsComputer.class.getName());

public JCloudsComputer(Slave slave) {
public JCloudsComputer(JCloudsSlave slave) {
super(slave);
}

Expand All @@ -29,7 +30,7 @@ public String getInstanceId() {

@Override
public JCloudsSlave getNode() {
return (JCloudsSlave) super.getNode();
return super.getNode();
}

public int getRetentionTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,18 @@

import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.slaves.OfflineCause;
import hudson.tasks.BuildTrigger;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;

import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import jenkins.plugins.jclouds.compute.internal.NodePlan;
import jenkins.plugins.jclouds.compute.internal.ProvisionPlannedInstancesAndDestroyAllOnError;
import jenkins.plugins.jclouds.compute.internal.RunningNode;
import jenkins.plugins.jclouds.compute.internal.TerminateNodes;
import jenkins.plugins.jclouds.internal.BuildListenerLogger;

import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.NodeMetadata;

import org.kohsuke.stapler.DataBoundConstructor;

import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.util.concurrent.MoreExecutors;

public class JCloudsOneOffSlave extends BuildWrapper {
private static final Logger LOGGER = Logger.getLogger(JCloudsOneOffSlave.class.getName());

Expand All @@ -51,6 +26,7 @@ public JCloudsOneOffSlave() {
// possible, as this method is very hard to test due to static usage, etc.
//
@Override
@SuppressWarnings("rawtypes")
public Environment setUp(AbstractBuild build, Launcher launcher, final BuildListener listener) {
if (JCloudsComputer.class.isInstance(build.getExecutor().getOwner())) {
final JCloudsComputer c = (JCloudsComputer) build.getExecutor().getOwner();
Expand All @@ -77,6 +53,7 @@ public String getDisplayName() {
}

@Override
@SuppressWarnings("rawtypes")
public boolean isApplicable(AbstractProject item) {
return true;
}
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlave.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package jenkins.plugins.jclouds.compute;

import hudson.Extension;
import hudson.model.Computer;
import hudson.model.TaskListener;
import hudson.model.Descriptor;
import hudson.model.Slave;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.AbstractCloudComputer;
import hudson.slaves.AbstractCloudSlave;
import hudson.slaves.NodeProperty;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.RetentionStrategy;

import java.io.IOException;
Expand All @@ -23,20 +24,21 @@
*
* @author Vijay Kiran
*/
public class JCloudsSlave extends Slave {
public class JCloudsSlave extends AbstractCloudSlave {
private static final Logger LOGGER = Logger.getLogger(JCloudsSlave.class.getName());
private transient NodeMetadata nodeMetaData;
public final boolean stopOnTerminate;
private String cloudName;
private final String cloudName;
private String nodeId;
private boolean pendingDelete;
private int overrideRetentionTime;
private String user;
private String password;
private String privateKey;
private boolean authSudo;
private final int overrideRetentionTime;
private final String user;
private final String password;
private final String privateKey;
private final boolean authSudo;

@DataBoundConstructor
@SuppressWarnings("rawtypes")
public JCloudsSlave(String cloudName, String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString,
ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties, boolean stopOnTerminate,
int overrideRetentionTime, String user, String password, String privateKey, boolean authSudo) throws Descriptor.FormException, IOException {
Expand Down Expand Up @@ -144,7 +146,7 @@ public void setPendingDelete(boolean pendingDelete) {
* {@inheritDoc}
*/
@Override
public Computer createComputer() {
public AbstractCloudComputer<JCloudsSlave> createComputer() {
LOGGER.info("Creating a new JClouds Slave");
return new JCloudsComputer(this);
}
Expand All @@ -153,6 +155,7 @@ public Computer createComputer() {
* Destroy the node calls {@link ComputeService#destroyNode}
*
*/
@Override
public void terminate() {
final ComputeService compute = JCloudsCloud.getByName(cloudName).getCompute();
if (compute.getNodeMetadata(nodeId) != null && compute.getNodeMetadata(nodeId).getStatus().equals(NodeMetadata.Status.RUNNING)) {
Expand Down Expand Up @@ -184,4 +187,10 @@ public boolean isInstantiable() {
return false;
}
}

@Override
protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ private RuntimeException destroyBadNodesAndPropagate(RunNodesException e) {
throw propagate(e);
}

@SuppressWarnings("unchecked")
public Descriptor<JCloudsSlaveTemplate> getDescriptor() {
return Jenkins.getInstance().getDescriptor(getClass());
}
Expand Down

0 comments on commit 54258e7

Please sign in to comment.