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

Commit

Permalink
Merge pull request #119 from rndsolutions/HTTPEndpoints-74
Browse files Browse the repository at this point in the history
Http endpoints 74
  • Loading branch information
VladislavNikolov authored Aug 1, 2016
2 parents 43168b7 + f4b3dac commit 91a6a59
Show file tree
Hide file tree
Showing 33 changed files with 3,623 additions and 212 deletions.
46 changes: 21 additions & 25 deletions Agent/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,12 @@
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

Expand All @@ -48,7 +30,6 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -59,11 +40,26 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -89,7 +85,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand Down
8 changes: 4 additions & 4 deletions Agent/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windows variants
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
3 changes: 3 additions & 0 deletions Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ dependencies {

compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.2'

compile group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-grizzly2', version: '2.23.1'

compile group: 'com.sun.jersey', name: 'jersey-client', version: '1.9.1'


// Jedis

compile 'redis.clients:jedis:2.8.0'
Expand Down
2 changes: 1 addition & 1 deletion Server/src/main/java/net/hawkengine/core/HawkServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void configureJetty() {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{"index.html"});
resourceHandler.setResourceBase(this.getClass().getResource("/dist").toExternalForm());
// resourceHandler.setResourceBase(this.getClass().getResource("/dist").toExternalForm());

// REST

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package net.hawkengine.core.utilities;

import net.hawkengine.model.*;
import net.hawkengine.model.Agent;
import net.hawkengine.model.ExecTask;
import net.hawkengine.model.FetchArtifactTask;
import net.hawkengine.model.FetchMaterialTask;
import net.hawkengine.model.JobDefinition;
import net.hawkengine.model.MaterialDefinition;
import net.hawkengine.model.PipelineDefinition;
import net.hawkengine.model.PipelineGroup;
import net.hawkengine.model.StageDefinition;
import net.hawkengine.model.TaskDefinition;
import net.hawkengine.model.UploadArtifactTask;

import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -33,6 +43,7 @@ public String validate(Object object) {
this.message = this.validate((TaskDefinition) object);
break;
case "MaterialDefinition":
case "GIT":
this.message = this.validate((MaterialDefinition) object);
break;
case "Agent":
Expand Down Expand Up @@ -287,43 +298,24 @@ private String validate(UploadArtifactTask uploadArtifactTask) {
return this.message;
}


// TODO: refactor MaterialDefinition validation
// public String validate(MaterialDefinition materialDefinition) {
// if (materialDefinition != null) {
// String materialName = materialDefinition.getName();
// if (materialName == null) {
// return this.message = "ERROR: MATERIAL DEFINITION NAME IS NULL.";
// }
//
// if (!this.isValidRegEx(materialName, NAME_PATTERN)) {
// return this.message = "ERROR: MATERIAL DEFINITION NAME IS INVALID.";
// }
//
// String materialURL = materialDefinition.getUrl();
// if (materialURL != null) {
//
// if (materialDefinition.getType() == MaterialType.GIT) {
// if (!this.isValidRegEx(materialURL, GIT_PATTERN)) {
// return this.message = "ERROR: INVALID GIT URL.";
// }
// } else if (materialDefinition.getType() == MaterialType.NUGET) {
// if (!this.isValidRegEx(materialURL, NUGET_PATTERN)) {
// return this.message = "ERROR: INVALID NUGET URL.";
// }
// } else {
// return this.message = "ERROR: MATERIAL URL IS INVALID.";
// }
// } else {
// return this.message = "ERROR: Material URL is NULL.";
// }
//
// } else {
// return this.message = "ERROR: Material Definition is NULL";
// }
//
// return this.message;
// }
public String validate(MaterialDefinition materialDefinition) {
if (materialDefinition != null) {
String materialName = materialDefinition.getName();
if (materialName == null) {
return this.message = "ERROR: MATERIAL DEFINITION NAME IS NULL.";
}

if (!this.isValidRegEx(materialName, NAME_PATTERN)) {
return this.message = "ERROR: MATERIAL DEFINITION NAME IS INVALID.";
}

} else {
return this.message = "ERROR: Material Definition is NULL";
}

return this.message;
}

public String validate(Agent agent) {
if (agent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public static void disconnect() {
redisEmbeddedDb.stop();
jedisPool.destroy();
}
}
}
37 changes: 19 additions & 18 deletions Server/src/main/java/net/hawkengine/http/AgentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import net.hawkengine.services.AgentService;
import net.hawkengine.services.PipelineService;
import net.hawkengine.services.interfaces.IPipelineService;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.util.List;

@Path("/agents")
@Consumes("application/json")
@Produces("application/json")
@Path("/agents")
public class AgentController {
private AgentService agentService;
private SchemaValidator schemaValidator;
Expand All @@ -28,10 +27,16 @@ public AgentController() {
this.pipelineService = new PipelineService();
}

public AgentController(AgentService agentService) {
this.agentService = agentService;
this.schemaValidator = new SchemaValidator();
this.pipelineService = new PipelineService();
}

@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getAllAgents() {
public Response getAllAgents() throws Throwable {
ServiceResult result = this.agentService.getAll();
return Response.status(Status.OK)
.entity(result.getObject())
Expand All @@ -46,8 +51,8 @@ public Response getById(@PathParam("agentId") String agentId) {
ServiceResult result = this.agentService.getById(agentId);
if (result.hasError()) {
return Response.status(Status.NOT_FOUND)
.entity(result)
.type(MediaType.TEXT_HTML)
.entity(result.getMessage())
.build();
}
return Response.status(Status.OK)
Expand All @@ -61,6 +66,11 @@ public Response getById(@PathParam("agentId") String agentId) {
@Path("/{agentId}/work")
public Response getWork(@PathParam("agentId") String agentId) {
ServiceResult result = this.agentService.getWorkInfo(agentId);
if (result.hasError()){
return Response.status(Status.BAD_REQUEST)
.entity(result.getMessage())
.build();
}
return Response.status(Status.OK)
.entity(result.getObject())
.build();
Expand All @@ -80,7 +90,7 @@ public Response addAgent(Agent agent) {
.build();
}

return Response.status(Status.OK)
return Response.status(Status.CREATED)
.entity(result.getObject())
.build();
} else {
Expand All @@ -96,7 +106,6 @@ public Response addAgent(Agent agent) {
@Produces(MediaType.APPLICATION_JSON)
@Path("/work")
public Response addWork(Job job) {

// TODO: Move logic into JobService
if (job == null) {
return Response.status(Status.OK).build();
Expand Down Expand Up @@ -144,25 +153,20 @@ public Response addWork(Job job) {
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{agentId}")
public Response updateAgent(Agent agent) {
String isValid = this.schemaValidator.validate(agent);
if (isValid.equals("OK")) {
ServiceResult result = this.agentService.update(agent);
if (result.hasError()) {
result = this.agentService.add(agent);
}

if (result.hasError()) {
return Response.status(Status.BAD_REQUEST)
return Response.status(Status.NOT_FOUND)
.entity(result.getMessage())
.type(MediaType.TEXT_HTML)
.build();
} else {
}
return Response.status(Status.OK)
.entity(result.getObject())
.build();
}

} else {
return Response.status(Status.BAD_REQUEST)
.entity(isValid)
Expand Down Expand Up @@ -227,11 +231,8 @@ public Response deleteAgent(@PathParam("agentId") String agentId) {
.entity(result.getMessage())
.type(MediaType.TEXT_HTML)
.build();
} else {
}
return Response.status(Status.NO_CONTENT)
.entity(result.getMessage())
.type(MediaType.TEXT_HTML)
.build();
}
}
}
53 changes: 53 additions & 0 deletions Server/src/main/java/net/hawkengine/http/JobController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.hawkengine.http;

import net.hawkengine.model.ServiceResult;
import net.hawkengine.services.JobService;
import net.hawkengine.services.interfaces.IJobService;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

@Path("/jobs")
public class JobController {
private IJobService jobService;

public JobController() {
this.jobService = new JobService();
}

public JobController(IJobService jobService) {
this.jobService = jobService;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAllJobs() {
ServiceResult response = this.jobService.getAll();
return Response.status(Status.OK).entity(response.getObject()).build();
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{jobId}")
public Response getJobById(@PathParam("jobId") String stageId) {
ServiceResult response = this.jobService.getById(stageId);
if (response.hasError()) {
return Response.status(Status.NOT_FOUND).entity(response.getMessage()).build();
}
return Response.status(Status.OK).entity(response.getObject()).build();
}
/*
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{jobId}/latest")
public Response getLatest(@PathParam("jobId") String stageId) {
// TODO: service to be implemented.
return Response.noContent().build();
}
*/
}
Loading

0 comments on commit 91a6a59

Please sign in to comment.