Skip to content

Commit

Permalink
Merge pull request #128 from kbss-cvut/fix/fta-fmea-ui-52-evaluate-fa…
Browse files Browse the repository at this point in the history
…ult-tree-fails-op-failure-rate

Continue evaluation of fault tree if operationalDataService.fetchFailureRates fails.
  • Loading branch information
blcham authored Jun 21, 2024
2 parents 5345d25 + dd43a53 commit b690e32
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
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
operationalFailureRateService: failure-rate

0 comments on commit b690e32

Please sign in to comment.