Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue evaluation of fault tree if operationalDataService.fetchFailureRates fails. #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cz.cvut.kbss.analysis.config.conf;

import cz.cvut.kbss.analysis.util.ConfigParam;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,10 +16,14 @@
public class OperationalDataConfig {

protected Double minOperationalHours;
protected String operationalDataServer;
protected String operationaDataServerCheck;
protected String operationalFailureRateService;

@Autowired
public OperationalDataConfig(Environment env) {
operationalFailureRateService = env.getProperty("operationalFailureRateService");
operationalDataServer = env.getProperty("operationalDataServer");
operationaDataServerCheck = env.getProperty("operationaDataServerCheck", "check");
operationalFailureRateService = env.getProperty("operationalFailureRateService", "failure-rate");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.service.OperationalDataFilterService;
import cz.cvut.kbss.analysis.service.external.OperationalDataService;
import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jsonld.JsonLd;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,10 +21,12 @@ public class OperationalDataFilterController {

private final OperationalDataFilterService filterService;
private final IdentifierService identifierService;
private final OperationalDataService operationalDataService;

public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService) {
public OperationalDataFilterController(OperationalDataFilterService filterService, IdentifierService identifierService, OperationalDataService operationalDataService) {
this.filterService = filterService;
this.identifierService = identifierService;
this.operationalDataService = operationalDataService;
}

@PutMapping(path="reset", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE})
Expand All @@ -46,4 +49,9 @@ public void updateFaultTreeFilter(@PathVariable(name = "faultTreeFragment") Stri
URI faultTreeUri = identifierService.composeIdentifier(Vocabulary.s_c_fault_tree, faultTreeFragment);
filterService.updateFaultTreeFilter(faultTreeUri, filter);
}

@GetMapping(value = "/check-service", produces = {MediaType.TEXT_PLAIN_VALUE})
public String checkOperationalDataService(){
return operationalDataService.checkConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ public void updateFaultTreeOperationalFailureRates(FaultTree faultTree, Operatio
return;

ItemFailureRate[] operationalFailureRateEstimates = operationalDataService.fetchFailureRates(filter, map.keySet());
if(operationalFailureRateEstimates == null)
return;

URI systemContext = getToolContext(faultTree.getSystem().getUri());
for(ItemFailureRate estimate : operationalFailureRateEstimates){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,41 @@ public OperationalDataService(OperationalDataConfig operationalDataConfig, Opera
this.restTemplate = restTemplate;
}

protected String getApi(String api){
String serverUri = operationalDataConfig.getOperationalDataServer();
return api == null || serverUri == null ? null : serverUri + api;
}


protected String getCheckApi(){
return getApi(operationalDataConfig.getOperationaDataServerCheck());
}

protected String getFailureRateApi(){
return getApi(operationalDataConfig.getOperationalFailureRateService());
}

public String checkConnection(){
String apiURI = getCheckApi();
if(apiURI == null) return "not connected";
try {
return restTemplate.getForObject(apiURI, String.class);
} catch (Exception e){
log.warn("Failed to fetch failure rates from " + apiURI, e);
}
return "not working";
}

public ItemFailureRate[] fetchFailureRates(OperationalDataFilter filter, Collection<URI> components){
String apiURI = operationalDataConfig.getOperationalFailureRateService();
Map<String, Object> uriParams = new HashMap<>();
uriParams.put("minOperationalTime", filter.getMinOperationalHours());
return restTemplate.postForObject(apiURI, components, ItemFailureRate[].class, uriParams);
String apiURI = getFailureRateApi();
if(apiURI == null) return null;
try {
Map<String, Object> uriParams = new HashMap<>();
uriParams.put("minOperationalTime", filter.getMinOperationalHours());
return restTemplate.postForObject(apiURI, components, ItemFailureRate[].class, uriParams);
} catch (Exception e){
log.warn("Failed to fetch failure rates from \"{}\" \nerror message: {}", apiURI, e.getMessage());
}
return null;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ spring:
operational.data.filter:
min-operational-hours: 200

operationalFailureRateService: https://kbss.onto.fel.cvut.cz/ava/services/ava-analytics/stats/failire-rate
operationalDataServer: https://kbss.felk.cvut.cz/ava/services/ava-analytics/stats/
operationaDataServerCheck: check
Comment on lines +45 to +46
Copy link
Contributor

@blcham blcham Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostobog Do not understand what is this good for ?!

operationalFailureRateService: failure-rate
Loading