-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from KPMP/KPMP-1128_StoreState
Kpmp 1128 store state
- Loading branch information
Showing
22 changed files
with
334 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
src/test/java/org/kpmp/stateManager/StateControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |