Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
GUVNOR-3258: UI Runtime Start/Stop/Remove operations (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedvede authored and porcelli committed Aug 8, 2017
1 parent 899edbe commit bf66ae0
Show file tree
Hide file tree
Showing 103 changed files with 4,921 additions and 871 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Optional<ProjectConfig> apply(final Source source,

final Collection<PlugIn> buildPlugins = extractPlugins(project);

final String expectedBinary = project.getArtifact().getArtifactId() + "-" + project.getArtifact().getVersion() + "." + project.getArtifact().getType();
final String expectedBinary = project.getArtifact().getArtifactId() + "-" + project.getArtifact().getVersion() + "." + calculateExtension(project.getArtifact().getType());
final String _tempDir = mavenProjectConfig.getProjectTempDir().trim();

final RepositoryVisitor repositoryVisitor;
Expand Down Expand Up @@ -150,4 +150,8 @@ public String outputId() {
public String inputId() {
return "maven-config";
}

private String calculateExtension(String artifactType) {
return "kjar".equals(artifactType) ? "jar" : artifactType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@

package org.guvnor.ala.services.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
Expand Down Expand Up @@ -55,6 +50,8 @@
import org.junit.Before;
import org.junit.Ignore;

import static org.junit.Assert.*;

public class PipelineEndpointsTestIT {

private final String APP_URL = "http://localhost:8080/api/";
Expand Down Expand Up @@ -149,7 +146,8 @@ public void checkService() {
assertEquals(1,
allRuntimes.getItems().size());

proxyRuntime.destroyRuntime(allRuntimes.getItems().get(0).getId());
proxyRuntime.destroyRuntime(allRuntimes.getItems().get(0).getId(),
true);

allRuntimes = proxyRuntime.getRuntimes(0,
10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

package org.guvnor.ala.services.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
Expand All @@ -50,6 +45,8 @@
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.junit.Ignore;

import static org.junit.Assert.*;

public class RuntimeEndpointsTestIT {

private final String APP_URL = "http://localhost:8080/api/";
Expand Down Expand Up @@ -86,22 +83,34 @@ public void checkOpenShiftService() throws Exception {
allProviders.getItems().size());
assertTrue(allProviders.getItems().get(0) instanceof OpenShiftProvider);
OpenShiftProvider openshiftProvider = (OpenShiftProvider) allProviders.getItems().get(0);
OpenShiftRuntimeConfig runtimeConfig = createRuntimeConfig(openshiftProvider, "coss1");
OpenShiftRuntimeConfig runtimeConfig = createRuntimeConfig(openshiftProvider,
"coss1");

@SuppressWarnings("unused")
OpenShiftRuntime openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
OpenShiftRuntime openshiftRuntime = getOpenShiftRuntime(proxy,
0,
null);

String runtimeId = proxy.newRuntime(runtimeConfig);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);
openshiftRuntime = getOpenShiftRuntime(proxy,
1,
OpenShiftRuntimeState.READY);

proxy.startRuntime(runtimeId);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.STARTED);
openshiftRuntime = getOpenShiftRuntime(proxy,
1,
OpenShiftRuntimeState.STARTED);

proxy.stopRuntime(runtimeId);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);

proxy.destroyRuntime(runtimeId);
openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
openshiftRuntime = getOpenShiftRuntime(proxy,
1,
OpenShiftRuntimeState.READY);

proxy.destroyRuntime(runtimeId,
true);
openshiftRuntime = getOpenShiftRuntime(proxy,
0,
null);
}

private OpenShiftProviderConfigImpl createProviderConfig() {
Expand All @@ -113,7 +122,8 @@ private OpenShiftProviderConfigImpl createProviderConfig() {
return openshiftProviderConfig;
}

private OpenShiftRuntimeConfigImpl createRuntimeConfig(ProviderId providerId, String testName) throws Exception {
private OpenShiftRuntimeConfigImpl createRuntimeConfig(ProviderId providerId,
String testName) throws Exception {
final String prjName = createProjectName(testName);
final String appName = "myapp";
final String svcName = appName + "-execserv";
Expand All @@ -126,17 +136,23 @@ private OpenShiftRuntimeConfigImpl createRuntimeConfig(ProviderId providerId, St
runtimeConfig.setResourceStreamsUri(getUri("jboss-image-streams.json"));
runtimeConfig.setResourceTemplateUri(getUri("bpmsuite70-execserv.json"));
runtimeConfig.setResourceTemplateParamValues(new OpenShiftParameters()
.param("APPLICATION_NAME", appName)
.param("IMAGE_STREAM_NAMESPACE", prjName)
.param("KIE_ADMIN_PWD", "admin1!")
.param("KIE_SERVER_PWD", "execution1!")
.toString());
.param("APPLICATION_NAME",
appName)
.param("IMAGE_STREAM_NAMESPACE",
prjName)
.param("KIE_ADMIN_PWD",
"admin1!")
.param("KIE_SERVER_PWD",
"execution1!")
.toString());
return runtimeConfig;
}

private String createProjectName(String testName) {
return new StringBuilder()
.append(System.getProperty("user.name", "anon").replaceAll("[^A-Za-z0-9]", "-"))
.append(System.getProperty("user.name",
"anon").replaceAll("[^A-Za-z0-9]",
"-"))
.append('-')
.append(testName != null ? testName : "test")
.append('-')
Expand All @@ -155,11 +171,11 @@ private OpenShiftRuntime getOpenShiftRuntime(RuntimeProvisioningService proxy,
int expectedCount,
String expectedState) {
RuntimeList allRuntimes = proxy.getRuntimes(0,
10,
"",
true);
10,
"",
true);
assertEquals(expectedCount,
allRuntimes.getItems().size());
allRuntimes.getItems().size());

if (expectedCount == 0) {
return null;
Expand All @@ -170,7 +186,7 @@ private OpenShiftRuntime getOpenShiftRuntime(RuntimeProvisioningService proxy,
assertTrue(runtime instanceof OpenShiftRuntime);
OpenShiftRuntime openshiftRuntime = (OpenShiftRuntime) runtime;
assertEquals(expectedState,
openshiftRuntime.getState().getState());
openshiftRuntime.getState().getState());

return openshiftRuntime;
}
Expand Down Expand Up @@ -246,7 +262,8 @@ public void checkDockerService() {
assertEquals("Stopped",
dockerRuntime.getState().getState());

proxy.destroyRuntime(newRuntime);
proxy.destroyRuntime(newRuntime,
true);

allRuntimes = proxy.getRuntimes(0,
10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.guvnor.ala.runtime.RuntimeState.RUNNING;
import static org.guvnor.ala.util.RuntimeConfigHelper.buildRuntimeName;

public class DockerRuntimeExecExecutor<T extends DockerRuntimeConfig>
Expand Down Expand Up @@ -142,7 +143,7 @@ private Optional<DockerRuntime> create(final DockerRuntimeConfig runtimeConfig)
dockerProvider,
dockerRuntimeEndpoint,
new DockerRuntimeInfo(),
new DockerRuntimeState("Running",
new DockerRuntimeState(RUNNING,
new Date().toString())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.guvnor.ala.runtime.RuntimeState.RUNNING;
import static org.guvnor.ala.runtime.RuntimeState.STOPPED;

public class DockerRuntimeManager implements RuntimeManager {

private final RuntimeRegistry runtimeRegistry;
Expand Down Expand Up @@ -101,9 +104,9 @@ public void refresh(RuntimeId runtimeId) throws RuntimeOperationException {
try {
ContainerInfo containerInfo = docker.getDockerClient(runtime.getProviderId()).inspectContainer(runtime.getId());
ContainerState state = containerInfo.state();
String stateString = "Stopped";
String stateString = STOPPED;
if (state.running() && !state.paused()) {
stateString = "Running";
stateString = RUNNING;
} else if (state.paused()) {
stateString = "Paused";
} else if (state.restarting()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.guvnor.ala.docker.executor;

import java.io.File;
Expand Down Expand Up @@ -47,6 +63,8 @@

import static java.util.Arrays.asList;
import static org.guvnor.ala.pipeline.StageUtil.config;
import static org.guvnor.ala.runtime.RuntimeState.RUNNING;
import static org.guvnor.ala.runtime.RuntimeState.STOPPED;
import static org.junit.Assert.*;

/**
Expand Down Expand Up @@ -162,7 +180,7 @@ public void testAPI() throws InterruptedException {

dockerRuntime = (DockerRuntime) runtime;

assertEquals("Running",
assertEquals(RUNNING,
dockerRuntime.getState().getState());

runtimeManager.stop(dockerRuntime);
Expand All @@ -179,7 +197,7 @@ public void testAPI() throws InterruptedException {

dockerRuntime = (DockerRuntime) runtime;

assertEquals("Stopped",
assertEquals(STOPPED,
dockerRuntime.getState().getState());

dockerRuntimeExecExecutor.destroy(runtime);
Expand Down Expand Up @@ -255,7 +273,7 @@ public void testFlexAPI() throws InterruptedException {

dockerRuntime = (DockerRuntime) runtime;

assertEquals("Running",
assertEquals(RUNNING,
dockerRuntime.getState().getState());

runtimeManager.stop(dockerRuntime);
Expand All @@ -272,7 +290,7 @@ public void testFlexAPI() throws InterruptedException {

dockerRuntime = (DockerRuntime) runtime;

assertEquals("Stopped",
assertEquals(STOPPED,
dockerRuntime.getState().getState());

dockerRuntimeExecExecutor.destroy(runtime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.guvnor.ala.registry.vfs;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

Expand All @@ -35,6 +34,7 @@
import org.uberfire.java.nio.file.FileSystem;
import org.uberfire.java.nio.file.Path;

import static org.guvnor.ala.AlaSPITestCommons.mockList;
import static org.guvnor.ala.registry.vfs.VFSRegistryHelper.PROVISIONING_BRANCH;
import static org.guvnor.ala.registry.vfs.VFSRegistryHelper.PROVISIONING_PATH;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -302,13 +302,4 @@ private void prepareReadEntries() throws Exception {
when(marshaller.unmarshal(MARSHALLED_VALUE + i)).thenReturn(expectedObjects.get(i));
}
}

private <T> List<T> mockList(Class<T> clazz,
int count) {
List<T> result = new ArrayList<>();
for (int i = 0; i < count; i++) {
result.add(mock(clazz));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
Expand Down Expand Up @@ -120,15 +122,36 @@ String newPipeline(@NotNull PipelineConfig config,

/**
* Run/Execute a registered Pipeline.
* @param id of the pipeline to be executed.
* @param pipelineId of the pipeline to be executed.
* @param input Input values to be used for the pipeline execution.
* @param async establishes the execution mode. true for asynchronous execution, false for synchronous execution.
* @return the pipeline execution id.
*/
@POST
@Consumes(value = APPLICATION_JSON)
@Produces(value = APPLICATION_JSON)
@Path("{id}")
String runPipeline(@PathParam("id") String id,
@Path("execution/{pipelineId}/run")
String runPipeline(@PathParam("pipelineId") String pipelineId,
@NotNull Input input,
@NotNull boolean async) throws BusinessException;

/**
* Stops a running pipeline execution.
* @param executionId A pipeline execution id to stop. The pipeline execution id is typically returned by
* the runPipeline method.
* @throws BusinessException
*/
@PUT
@Path("execution/{executionId}/stop")
void stopPipelineExecution(@PathParam("executionId") String executionId) throws BusinessException;

/**
* Deletes a pipeline execution
* @param executionId A pipeline execution id to delete. The pipeline execution id is typically returned by
* the runPipeline method.
* @throws BusinessException
*/
@DELETE
@Path("execution/{executionId}")
void deletePipelineExecution(@PathParam("executionId") String executionId) throws BusinessException;
}
Loading

0 comments on commit bf66ae0

Please sign in to comment.