Skip to content

Commit

Permalink
Merge pull request #20 from KPMP/KPMP-3820_Set_Error
Browse files Browse the repository at this point in the history
Kpmp 3820 set error
  • Loading branch information
rlreamy authored Oct 12, 2022
2 parents 61e3710 + d55e8c2 commit a0f0d6a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/kpmp/FailedPackageChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.kpmp.stateManager.DluPackageInventoryService;
import org.kpmp.stateManager.State;
import org.kpmp.stateManager.StateService;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -21,6 +22,8 @@ public class FailedPackageChecker implements CommandLineRunner {

private StateService stateService;

private DluPackageInventoryService dluPackageInventoryService;

private static final Log log = LogFactory.getLog(FailedPackageChecker.class);

@Value("${state.service.host}")
Expand All @@ -40,9 +43,10 @@ public class FailedPackageChecker implements CommandLineRunner {

private RestTemplate restTemplate;

public FailedPackageChecker(StateService stateService, RestTemplate restTemplate) {
public FailedPackageChecker(StateService stateService, RestTemplate restTemplate, DluPackageInventoryService dluPackageInventoryService) {
this.stateService = stateService;
this.restTemplate = restTemplate;
this.dluPackageInventoryService = dluPackageInventoryService;
}

public static void main(String[] args) {
Expand Down Expand Up @@ -103,6 +107,7 @@ public void run(String... args) throws Exception {
failedState.setStateChangeDate(new Date());
failedState.setCodicil("Failed stale package check");
sendStateChange(failedState);
dluPackageInventoryService.setPackageInError(state.getPackageId());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.kpmp.stateManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

@Service
public class DluPackageInventoryService {

@Value("${data-manager.service.host}")
private String dataManagerHost;
@Value("${data-manager.service.endpoint}")
private String dataManagerEndpoint;
private RestTemplate restTemplate;

private static final Log log = LogFactory.getLog(DluPackageInventoryService.class);

@Autowired
public DluPackageInventoryService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}

public String setPackageInError(String packageId) {
HashMap payload = new HashMap<>();
payload.put("dlu_error", true);
String retPackageId = null;
String url = dataManagerHost + dataManagerEndpoint + "/package/" + packageId;
try {
retPackageId = restTemplate.postForObject(url, payload, String.class);
} catch (Exception e) {
log.error("URI: " + url + " | PKGID: " + packageId + " | MSG: Setting DMD package error");
}
return retPackageId;
}
}
7 changes: 5 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ file.base.path=/data/dataLake
spring.main.banner-mode=off

state.service.host=http://localhost:3060
state.service.endpoint=/v1/state/host,v1/clearCache
state.service.endpoint=/v1/state/host

notification.service.host=http://eridanus-spring:3040
notification.endpoint=/v2/notifications/package

data-manager.service.host=http://data-manager-service:5000
data-manager.service.endpoint=/v1/dlu

spring.data.mongodb.uri=mongodb://mongodb:27017/dataLake

package.state.metadata.received=METADATA_RECEIVED
Expand All @@ -19,4 +22,4 @@ package.state.upload.failed=UPLOAD_FAILED

package.state.longpoll.timeout=60000
package.state.checker.timeout=1800000
package.state.checker.checkaftermillis=86400000
package.state.checker.checkaftermillis=86400000
5 changes: 4 additions & 1 deletion src/test/java/FailedPackageCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import org.junit.Before;
import org.junit.Test;
import org.kpmp.FailedPackageChecker;
import org.kpmp.stateManager.DluPackageInventoryService;
import org.kpmp.stateManager.State;
import org.kpmp.stateManager.StateService;
import org.mockito.Mock;
Expand All @@ -16,6 +17,8 @@
public class FailedPackageCheckerTest {


@Mock
DluPackageInventoryService dluPackageInventoryService;
@Mock
private StateService service;
@Mock
Expand All @@ -27,7 +30,7 @@ public class FailedPackageCheckerTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
packageChecker = new FailedPackageChecker(service, restTemplate);
packageChecker = new FailedPackageChecker(service, restTemplate, dluPackageInventoryService);
}

@After
Expand Down

0 comments on commit a0f0d6a

Please sign in to comment.