use of cz.metacentrum.perun.controller.model.FacilityState in project perun by CESNET.
the class TasksManagerBlImpl method getAllFacilitiesStates.
@Override
public List<FacilityState> getAllFacilitiesStates(PerunSession session) throws FacilityNotExistsException {
List<FacilityState> list = new ArrayList<>();
// return facilities where user is admin or all if perun admin
List<Facility> facs = perun.getFacilitiesManagerBl().getFacilities(session);
Collections.sort(facs);
for (Facility facility : facs) {
list.add(getFacilityState(session, facility));
}
return list;
}
use of cz.metacentrum.perun.controller.model.FacilityState in project perun by CESNET.
the class TasksManagerBlImpl method getAllFacilitiesStatesForVo.
@Override
public List<FacilityState> getAllFacilitiesStatesForVo(PerunSession session, Vo vo) throws VoNotExistsException, FacilityNotExistsException {
perun.getVosManagerBl().checkVoExists(session, vo);
List<FacilityState> list = new ArrayList<>();
List<RichResource> facs = perun.getResourcesManagerBl().getRichResources(session, vo);
Set<Facility> facilities = new HashSet<>();
for (RichResource res : facs) {
facilities.add(res.getFacility());
}
for (Facility f : facilities) {
list.add(getFacilityState(session, f));
}
Collections.sort(list);
return list;
}
use of cz.metacentrum.perun.controller.model.FacilityState in project perun by CESNET.
the class PropagationStatsReaderImpl method getFacilityState.
@Override
public FacilityState getFacilityState(PerunSession session, Facility facility) throws PrivilegeException, FacilityNotExistsException, InternalErrorException {
// get all tasks
List<Task> tasks = taskDao.listAllTasksForFacility(facility.getId());
// define state
FacilityState state = new FacilityState();
state.setFacility(facility);
// if no tasks we can't determine facility state
if (tasks.isEmpty() || tasks == null) {
state.setState(FacilityPropagationState.NOT_DETERMINED);
return state;
} else {
// OK if no change
state.setState(FacilityPropagationState.OK);
}
// fill all available destinations
List<RichDestination> destinations = perun.getServicesManager().getAllRichDestinations(session, facility);
for (RichDestination rd : destinations) {
state.getResults().put(rd.getDestination(), FacilityPropagationState.NOT_DETERMINED);
}
// magic with tasks :-)
for (Task task : tasks) {
// save previous facility state
FacilityPropagationState facState = state.getState();
// PROCESSING and not ERROR before
if (TaskStatus.PROCESSING.equals(task.getStatus()) && (facState != FacilityPropagationState.ERROR)) {
state.setState(FacilityPropagationState.PROCESSING);
} else // ERROR - set ERROR
if (TaskStatus.ERROR.equals(task.getStatus())) {
state.setState(FacilityPropagationState.ERROR);
}
// get destination status
if (task.getExecService().getExecServiceType().equals(ExecService.ExecServiceType.SEND)) {
List<TaskResult> results = taskResultDao.getTaskResultsByTask(task.getId());
Map<Service, Map<Destination, TaskResult>> latestResults = new HashMap<Service, Map<Destination, TaskResult>>();
for (TaskResult res : results) {
if (latestResults.get(res.getService()) == null) {
// put in map since result for service exists
Map<Destination, TaskResult> value = new HashMap<>();
value.put(res.getDestination(), res);
latestResults.put(res.getService(), value);
} else if (latestResults.get(res.getService()) != null && latestResults.get(res.getService()).get(res.getDestination()) == null) {
// put in inner map, since destination for service not yet exists
latestResults.get(res.getService()).put(res.getDestination(), res);
} else {
// update in inner map since this is later task result
if (latestResults.get(res.getService()).get(res.getDestination()).getId() < res.getId()) {
// put in map
latestResults.get(res.getService()).put(res.getDestination(), res);
}
}
}
for (Map<Destination, TaskResult> res : latestResults.values()) {
for (TaskResult result : res.values()) {
// iterate over all latest tasks results
String destination = result.getDestination().getDestination();
FacilityPropagationState propState = state.getResults().get(destination);
// if any error => state is error
if (TaskResult.TaskResultStatus.ERROR.equals(result.getStatus())) {
state.getResults().put(destination, FacilityPropagationState.ERROR);
continue;
}
// if result ok and previous was not bad
if (TaskResult.TaskResultStatus.DONE.equals(result.getStatus())) {
if (FacilityPropagationState.NOT_DETERMINED.equals(propState)) {
state.getResults().put(destination, FacilityPropagationState.OK);
}
}
}
}
}
}
return state;
}
use of cz.metacentrum.perun.controller.model.FacilityState in project perun by CESNET.
the class TasksManagerBlImpl method getFacilityState.
@Override
public FacilityState getFacilityState(PerunSession session, Facility facility) throws FacilityNotExistsException {
perun.getFacilitiesManagerBl().checkFacilityExists(session, facility);
// get all tasks
List<Task> tasks = getTasksManagerImpl().listAllTasksForFacility(facility.getId());
// define state
FacilityState state = new FacilityState();
state.setFacility(facility);
// if no tasks we can't determine facility state
if (tasks == null || tasks.isEmpty()) {
state.setState(FacilityState.FacilityPropagationState.NOT_DETERMINED);
return state;
} else {
// OK if no change
state.setState(FacilityState.FacilityPropagationState.OK);
}
// fill all available destinations
List<RichDestination> destinations = perun.getServicesManagerBl().getAllRichDestinations(session, facility);
for (RichDestination rd : destinations) {
state.getResults().put(rd.getDestination(), FacilityState.FacilityPropagationState.NOT_DETERMINED);
}
// magic with tasks :-)
for (Task task : tasks) {
// save previous facility state
FacilityState.FacilityPropagationState facState = state.getState();
// PROCESSING and not ERROR before
if (Arrays.asList(Task.TaskStatus.GENERATED, Task.TaskStatus.GENERATING, Task.TaskStatus.PLANNED, Task.TaskStatus.SENDING).contains(task.getStatus()) && (facState != FacilityState.FacilityPropagationState.ERROR)) {
state.setState(FacilityState.FacilityPropagationState.PROCESSING);
} else // ERROR - set ERROR
if (Arrays.asList(Task.TaskStatus.ERROR, Task.TaskStatus.GENERROR, Task.TaskStatus.SENDERROR).contains(task.getStatus())) {
state.setState(FacilityState.FacilityPropagationState.ERROR);
}
// get destination status
if (task.getService() != null) {
List<TaskResult> results = getTasksManagerImpl().getTaskResultsByTask(task.getId());
Map<Service, Map<Destination, TaskResult>> latestResults = new HashMap<>();
for (TaskResult res : results) {
if (latestResults.get(res.getService()) == null) {
// put in map since result for service exists
Map<Destination, TaskResult> value = new HashMap<>();
value.put(res.getDestination(), res);
latestResults.put(res.getService(), value);
} else if (latestResults.get(res.getService()) != null && latestResults.get(res.getService()).get(res.getDestination()) == null) {
// put in inner map, since destination for service not yet exists
latestResults.get(res.getService()).put(res.getDestination(), res);
} else {
// update in inner map since this is later task result
if (latestResults.get(res.getService()).get(res.getDestination()).getId() < res.getId()) {
// put in map
latestResults.get(res.getService()).put(res.getDestination(), res);
}
}
}
for (Map<Destination, TaskResult> res : latestResults.values()) {
for (TaskResult result : res.values()) {
// iterate over all latest tasks results
String destination = result.getDestination().getDestination();
FacilityState.FacilityPropagationState propState = state.getResults().get(destination);
// if any error => state is error
if (TaskResult.TaskResultStatus.ERROR.equals(result.getStatus())) {
state.getResults().put(destination, FacilityState.FacilityPropagationState.ERROR);
continue;
}
// if result ok and previous was not bad
if (TaskResult.TaskResultStatus.DONE.equals(result.getStatus())) {
if (FacilityState.FacilityPropagationState.NOT_DETERMINED.equals(propState)) {
state.getResults().put(destination, FacilityState.FacilityPropagationState.OK);
}
}
}
}
}
}
return state;
}
use of cz.metacentrum.perun.controller.model.FacilityState in project perun by CESNET.
the class TasksManagerBlImplTest method testGetFacilityState.
@Test
public void testGetFacilityState() {
System.out.println("TasksManagerBlImplTest.testGetFacilityState");
// TODO - add more thorough test
assertThatNoException().isThrownBy(() -> {
FacilityState state = tasksManager.getFacilityState(perunSession, facility1);
assertEquals(facility1, state.getFacility());
assertEquals(FacilityPropagationState.OK, state.getState());
});
}
Aggregations