Skip to content

Commit

Permalink
Merge pull request #2 from KPMP/KPMP-1128_StoreState
Browse files Browse the repository at this point in the history
Kpmp 1128 store state
  • Loading branch information
zwright authored Sep 4, 2019
2 parents f9319dc + f1023f8 commit 456a78a
Show file tree
Hide file tree
Showing 22 changed files with 334 additions and 6 deletions.
Binary file modified .gradle/4.6/fileContent/annotation-processors.bin
Binary file not shown.
Binary file modified .gradle/4.6/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency

COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-cp","app:app/lib/*","org.kpmp.Application"]
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# stateManagerService
# State Manager Service

This is intended to be a service available to other services and applications inside of KPMP. It is not a stand-alone website, so there is only a Java project for the service layer.

The state manager service will do the work to keep track of the state of packages as they travel from the data lake to the knowledge environment.
It will run inside the dataLake network which is created by orion when running on a developer machine, or by the dataLakeProxyServer when running on our production-like and production instances.

## Set up on your local machine

- Change directory to heavens-docker/orion
- docker-compose -f docker-compose.dev.yml up -d
- Change directory to heavens-docker/stateManager
- docker-compose -f docker-compose.dev.yml up -d

At this point you should be able to interact with the service by hitting endpoints at http://localhost:3060

As you are working on changes, you should make sure to run ./gradlew build docker in order to create new docker images locally to be used inside docker. After rebuilding the image, you will need to restart the docker container in order to pick up your changes.

When you are done with your local changes, you will need to push the latest image to cloud.docker.com

1) docker login
2) Provide username/password (see another developer for these values)
3) docker push kingstonduo/state-manager-service // This will push to the 'latest' tag which we are using on our local development machines
4) docker image ls
5) Find the image you just built (should be at the top of the list) and grab the hash
6) docker tag <hash> kingstonduo/state-manager-service:<x.x> // Where hash is the value you just grabbed, and x.x is the release version you are working on
7) docker push kingstonduo/state-manager-service:<x.x>

## Set up in dev, qa or prod

- Pull down the stateManagerService project at http://github.com/KPMP
- Change directory to heavens-docker/dataLakeProxyServer
- docker-compose up -d
- Change directory to heavens-docker/ara
- docker-compose up -d
- Change directory to heavens-docker/orion
- docker-compose -f docker-compose.shib.yml up -d
- Change directory to heavens-docker/stateManager
- docker-compose -f docker-compose.prod.yml up -d
~
3 changes: 3 additions & 0 deletions bin/default/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server.port=3060

spring.data.mongodb.uri=mongodb://mongodb:27017/dataLake
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.docker'

jar {
baseName='stateManagerService'
version= '0.1'
baseName='state-manager-service'
version= '1.0'
}

repositories {
Expand All @@ -38,7 +38,7 @@ dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.apache.commons:commons-compress:1.17'
compile 'org.springframework.boot:spring-boot-starter-test'
compile 'org.springframework.data:spring-data-mongodb:2.0.8.RELEASE'
compile 'org.springframework.data:spring-data-mongodb'
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.mockito:mockito-core'
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/kpmp/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.kpmp;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableAutoConfiguration(exclude = {})
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
public class WebConfig implements WebMvcConfigurer {

@Override
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/kpmp/stateManager/State.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.kpmp.stateManager;

import java.util.Date;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "state")
public class State {

@Id
private String id;
private String packageId;
private String state;
private String codicil;
private Date stateChangeDate;

public Date getStateChangeDate() {
return stateChangeDate;
}

public void setStateChangeDate(Date stateChangeDate) {
this.stateChangeDate = stateChangeDate;
}

public String getCodicil() {
return codicil;
}

public void setCodicil(String codicil) {
this.codicil = codicil;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getPackageId() {
return packageId;
}

public void setPackageId(String packageId) {
this.packageId = packageId;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

}
35 changes: 35 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.kpmp.stateManager;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StateController {

private StateService stateService;
private static final Log log = LogFactory.getLog(StateController.class);

@Autowired
public StateController(StateService stateService) {
this.stateService = stateService;
}

@RequestMapping(value = "/v1/state", method = RequestMethod.POST)
public @ResponseBody String setState(@RequestBody State state, HttpServletRequest request) {
log.info("URI: " + request.getRequestURI() + " | PKGID: " + state.getPackageId() + " | MSG: Saving new state: "
+ state.getState());
state.setStateChangeDate(new Date());
return stateService.setState(state);
}

}
10 changes: 10 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.kpmp.stateManager;

import org.springframework.data.mongodb.repository.MongoRepository;

public interface StateRepository extends MongoRepository<State, String> {

@SuppressWarnings("unchecked")
public State save(State state);

}
21 changes: 21 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.kpmp.stateManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StateService {

private StateRepository stateRepository;

@Autowired
public StateService(StateRepository stateRepository) {
this.stateRepository = stateRepository;
}

public String setState(State state) {
State savedState = stateRepository.save(state);
return savedState.getId();
}

}
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server.port=3060

spring.data.mongodb.uri=mongodb://mongodb:27017/dataLake
47 changes: 47 additions & 0 deletions src/test/java/org/kpmp/stateManager/StateControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class StateControllerTest {

@Mock
private StateService stateService;
private StateController controller;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
controller = new StateController(stateService);
}

@After
public void tearDown() throws Exception {
controller = null;
}

@Test
public void testSetState() {
State state = mock(State.class);
when(stateService.setState(state)).thenReturn("id");
String stateId = controller.setState(state, mock(HttpServletRequest.class));

assertEquals("id", stateId);
verify(stateService).setState(state);
verify(state).setStateChangeDate(any(Date.class));
}

}
44 changes: 44 additions & 0 deletions src/test/java/org/kpmp/stateManager/StateServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class StateServiceTest {

@Mock
private StateRepository stateRepository;
private StateService service;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
service = new StateService(stateRepository);
}

@After
public void tearDown() throws Exception {
service = null;
}

@Test
public void testSetState() {
State state = mock(State.class);
State returnState = mock(State.class);
when(returnState.getId()).thenReturn("id");
when(stateRepository.save(state)).thenReturn(returnState);

String stateId = service.setState(state);

assertEquals("id", stateId);
verify(stateRepository).save(state);
}

}
58 changes: 58 additions & 0 deletions src/test/java/org/kpmp/stateManager/StateTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class StateTest {

private State state;

@Before
public void setUp() throws Exception {
state = new State();
}

@After
public void tearDown() throws Exception {
state = null;
}

@Test
public void testSetStateChangeDate() {
Date stateChangeDate = new Date();

state.setStateChangeDate(stateChangeDate);

assertEquals(stateChangeDate, state.getStateChangeDate());
}

@Test
public void testSetCodicil() {
state.setCodicil("codicil");
assertEquals("codicil", state.getCodicil());
}

@Test
public void testSetState() {
state.setState("new state");
assertEquals("new state", state.getState());
}

@Test
public void testSetPackageId() {
state.setPackageId("packageId");
assertEquals("packageId", state.getPackageId());
}

@Test
public void testId() throws Exception {
state.setId("id");
assertEquals("id", state.getId());
}

}

0 comments on commit 456a78a

Please sign in to comment.