Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
</parent>

<artifactId>cloudshell-sandbox</artifactId>
<version>1.6.4-beta</version>
<version>1.8.3</version>
<packaging>hpi</packaging>


<properties>
<jenkins.version>2.9</jenkins.version>
<java.level>7</java.level>
<java.level>8</java.level>
<jenkins-test-harness.version>2.2</jenkins-test-harness.version>
</properties>

Expand Down Expand Up @@ -63,23 +64,22 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>

<dependency>
<groupId>com.quali.cloudshell</groupId>
<artifactId>sandbox-api</artifactId>
<version>1.1.0.14</version>
<version>1.3.0.2</version>
</dependency>

<dependency>
Expand All @@ -94,6 +94,21 @@
<version>2.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>


<dependency>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
<type>signature</type>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
Expand Down Expand Up @@ -147,8 +162,18 @@
<version>1.9</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<disabledTestInjection>true</disabledTestInjection>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,41 @@ public FormValidation doTestConnection(
return FormValidation.ok("Test completed successfully");
}

public FormValidation doCheckPw(@QueryParameter String value) {
if(value.isEmpty())
public FormValidation doCheckPw(@QueryParameter String value, @QueryParameter String serverAddress) {
if(serverAddress.isEmpty())
return FormValidation.ok();

if(value.isEmpty())
return FormValidation.errorWithMarkup("Password cannot be empty");
else
return FormValidation.ok();
}

public FormValidation doCheckUser(@QueryParameter String value) {
public FormValidation doCheckUser(@QueryParameter String value, @QueryParameter String serverAddress) {
if(serverAddress.isEmpty())
return FormValidation.ok();

if(value.isEmpty())
return FormValidation.errorWithMarkup("User cannot be empty");
else
return FormValidation.ok();
}

public FormValidation doCheckDomain(@QueryParameter String value) {
if(value.isEmpty())
public FormValidation doCheckDomain(@QueryParameter String value, @QueryParameter String serverAddress) {
if(serverAddress.isEmpty())
return FormValidation.ok();

if(value.isEmpty())
return FormValidation.errorWithMarkup("Domain cannot be empty");
else
return FormValidation.ok();
}


public FormValidation doCheckServerAddress(@QueryParameter String value) {
// String regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
if(value.isEmpty())
return FormValidation.ok();

String regex = "^(https?)://[-a-zA-Z0-9-_.:]*[0-9]";
if(value.matches(regex))
return FormValidation.ok();
Expand All @@ -140,6 +151,7 @@ public FormValidation doCheckServerAddress(@QueryParameter String value) {
}



@Override
public String getDisplayName() {
return "CloudShell Build Step";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package org.jenkinsci.plugins.cloudshell.builders;

import com.google.gson.Gson;
import com.quali.cloudshell.Constants;
import com.quali.cloudshell.QsServerDetails;
import com.quali.cloudshell.SandboxApiGateway;
import com.quali.cloudshell.qsExceptions.ExtendedSandboxApiException;
import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
Expand All @@ -36,6 +38,7 @@ public class StartSandbox extends CloudShellBuildStep {
private final String blueprintName;
private final String sandboxDuration;
private final int maxWaitForSandboxAvailability;
private int setupTimeout;

@CheckForNull
private String sandboxDomain;
Expand All @@ -45,10 +48,11 @@ public class StartSandbox extends CloudShellBuildStep {
private String params;

@DataBoundConstructor
public StartSandbox(String blueprintName, String sandboxDuration, int maxWaitForSandboxAvailability) {
public StartSandbox(String blueprintName, String sandboxDuration, int maxWaitForSandboxAvailability, int setupTimeout) {
this.blueprintName = blueprintName;
this.sandboxDuration = sandboxDuration;
this.maxWaitForSandboxAvailability = maxWaitForSandboxAvailability;
this.setupTimeout = setupTimeout;
}

public String getBlueprintName() {
Expand All @@ -60,6 +64,9 @@ public String getSandboxDuration() {
public int getMaxWaitForSandboxAvailability() {
return maxWaitForSandboxAvailability;
}
public int getSetupTimeout() {
return setupTimeout;
}

@CheckForNull
public String getParams() {
Expand Down Expand Up @@ -98,17 +105,30 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
server = new QsServerDetails(server.serverAddress, server.user, server.pw, sandboxDomain, server.ignoreSSL);
}

SandboxApiGateway gateway = new SandboxApiGateway(new QsJenkinsTaskLogger(listener), server);
String sandboxId = gateway.TryStartBlueprint(blueprintName,
Integer.parseInt(sandboxDuration),
true,
(sandboxName == null || sandboxName.isEmpty()) ? null : sandboxName,
gateway.TryParseBlueprintParams(params),
maxWaitForSandboxAvailability);

Gson gson = new Gson();
String sandboxDetails = gson.toJson(gateway.GetSandboxDetails(sandboxId));
addSandboxToBuildActions(build, server, sandboxId, sandboxDetails);
int customSetupTimeout =0;
if (setupTimeout == 0)
customSetupTimeout = Constants.CONNECT_TIMEOUT_SECONDS;
else
customSetupTimeout= setupTimeout*60;

SandboxApiGateway gateway = new SandboxApiGateway(new QsJenkinsTaskLogger(listener), server, customSetupTimeout);
String sandboxId = "";
try {
sandboxId = gateway.TryStartBlueprint(blueprintName,
Integer.parseInt(sandboxDuration),
true,
(sandboxName == null || sandboxName.isEmpty()) ? null : sandboxName,
gateway.TryParseBlueprintParams(params),
maxWaitForSandboxAvailability);
Gson gson = new Gson();
String sandboxDetails = gson.toJson(gateway.GetSandboxDetails(sandboxId));
addSandboxToBuildActions(build, server, sandboxId, sandboxDetails);
}
catch (ExtendedSandboxApiException e)
{
addSandboxToBuildActions(build, server, e.getSandboxId(), "");
throw e;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
import java.util.Arrays;
import java.util.List;

/**
* Post-build step that allow stop all matched container
*
* @author magnayn
*/
public class CloudShellPublisherControl extends Recorder implements Serializable {

@DataBoundConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public class SandboxStartStep extends AbstractStepImpl {
@CheckForNull
private String params;

private int setupTimeout;

@DataBoundConstructor
public SandboxStartStep(@Nonnull String name, int duration, int timeout) {
this.name = name;
this.duration = duration;
this.timeout = timeout;
}


@CheckForNull
public String getParams() {
return params;
Expand All @@ -55,6 +56,15 @@ public void setSandboxName(@CheckForNull String sandboxName) {
this.sandboxName = Util.fixNull(sandboxName);
}

public int getSetupTimeout() {
return setupTimeout;
}

@DataBoundSetter
public void setSetupTimeout( int setupTimeout) {
this.setupTimeout = setupTimeout;
}

@CheckForNull
public String getSandboxDomain() {
return sandboxDomain;
Expand Down Expand Up @@ -91,7 +101,7 @@ public static class SandboxStartStepExecution extends AbstractSynchronousStepExe
@Override
protected String run() throws Exception {
StepsCommon stepsCommon = new StepsCommon();
return stepsCommon.startSandbox(listener, step.name, step.duration ,step.params, step.sandboxName, step.timeout, step.sandboxDomain);
return stepsCommon.startSandbox(listener, step.name, step.duration ,step.params, step.sandboxName, step.timeout, step.sandboxDomain, step.setupTimeout*60);
}

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
package org.jenkinsci.plugins.cloudshell.steps;

import com.google.inject.Inject;
import com.quali.cloudshell.Constants;
import com.quali.cloudshell.qsExceptions.SandboxApiException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.TaskListener;
import jnr.constants.Constant;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.workflow.steps.*;
import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -53,7 +55,7 @@ public class SandboxStep extends AbstractStepImpl {

@Deprecated
@DataBoundConstructor
public SandboxStep(@Nonnull String name, int maxDuration, String params, String sandboxName, String sandboxDomain, int timeout) {
public SandboxStep(@Nonnull String name, int maxDuration, String params, String sandboxName, String sandboxDomain, int timeout) {
this.name = name;
this.maxDuration = maxDuration;
this.params = params;
Expand Down Expand Up @@ -99,7 +101,7 @@ public void stop(@Nonnull Throwable throwable) throws Exception {
listener.getLogger().println("Aborting CloudShell Sandbox!");
if (sandboxId != null && !sandboxId.isEmpty())
{
new StepsCommon().stopSandbox(listener, sandboxId, getContext());
new StepsCommon().stopSandbox(listener, sandboxId, getContext(), Constants.CONNECT_TIMEOUT_SECONDS);
}
}

Expand All @@ -110,7 +112,7 @@ private boolean CreateSandbox(StepsCommon stepsCommon) throws
KeyManagementException,
IOException, InterruptedException {

sandboxId = stepsCommon.startSandbox(listener, step.name, step.maxDuration, step.params, step.sandboxName, step.timeout);
sandboxId = stepsCommon.startSandbox(listener, step.name, step.maxDuration, step.params, step.sandboxName, step.timeout, step.sandboxDomain, Constants.CONNECT_TIMEOUT_SECONDS);
return false;
}

Expand All @@ -127,7 +129,7 @@ private static class Callback extends BodyExecutionCallback {

private void stopSandbox(StepContext context) {
StepsCommon stepsCommon = new StepsCommon();
stepsCommon.stopSandbox(listener, sandboxId, context);
stepsCommon.stopSandbox(listener, sandboxId, context, Constants.CONNECT_TIMEOUT_SECONDS);
}

@Override
Expand Down Expand Up @@ -192,6 +194,5 @@ public Step newInstance(StaplerRequest req, JSONObject formData) throws FormExce
String sandboxDomain = formData.getString("sandboxDomain");
return new SandboxStep(name, duration, params, sandboxName, sandboxDomain, timeout);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.Nonnull;

public class SandboxStopStep extends AbstractStepImpl {

public final String reservationId;
public final String sandboxId;

private int teardownTimeout;

@DataBoundConstructor
public SandboxStopStep(@Nonnull String reservationId) {
this.reservationId = reservationId;
public SandboxStopStep(@Nonnull String sandboxId) {
this.sandboxId = sandboxId;
}

public int getTeardownTimeout() {
return teardownTimeout;
}

@DataBoundSetter
public void setTeardownTimeout(int teardownTimeout) {
this.teardownTimeout = teardownTimeout;
}

@Extension
Expand All @@ -32,7 +44,7 @@ public DescriptorImpl() {
}

@Override public String getDisplayName() {
return "stops a cloudshell sandbox";
return "Stops a CloudShell Sandbox";
}
}

Expand All @@ -49,7 +61,7 @@ public static class SandboxStopStepExecution extends AbstractSynchronousStepExec
@Override
protected Void run() throws Exception {
StepsCommon stepsCommon = new StepsCommon();
stepsCommon.stopSandbox(listener, step.reservationId, getContext());
stepsCommon.stopSandbox(listener, step.sandboxId, getContext(), step.teardownTimeout*60);
return null;
}
}
Expand Down
Loading