use of cz.metacentrum.perun.taskslib.model.TaskResult in project perun by CESNET.
the class SchedulingPoolImpl method createTaskResult.
// TODO this does not belong here, move it somewhere else
@Override
public TaskResult createTaskResult(int taskId, int destinationId, String stderr, String stdout, int returnCode, Service service) {
TaskResult taskResult = new TaskResult();
taskResult.setTaskId(taskId);
taskResult.setDestinationId(destinationId);
taskResult.setErrorMessage(stderr);
taskResult.setStandardMessage(stdout);
taskResult.setReturnCode(returnCode);
taskResult.setStatus(returnCode == 0 ? ((stderr == null || stderr.isEmpty()) ? TaskResult.TaskResultStatus.DONE : TaskResult.TaskResultStatus.WARNING) : TaskResult.TaskResultStatus.ERROR);
taskResult.setTimestamp(new Date(System.currentTimeMillis()));
taskResult.setService(service);
return taskResult;
}
use of cz.metacentrum.perun.taskslib.model.TaskResult in project perun by CESNET.
the class AuditParserTest method sameObjectBeforeAndAfterSerializing.
@Test
public void sameObjectBeforeAndAfterSerializing() throws Exception {
System.out.println(CLASS_NAME + ":sameObjectBeforeAndAfterSerializing");
// FOR USER
User user = new User(8, null, textMismatch, null, textMismatch, null, true, true);
user.setUuid(UUID.randomUUID());
List<PerunBean> userInList = AuditParser.parseLog(user.serializeToString());
assertEquals(user.toString(), ((User) userInList.get(0)).toString());
assertEquals(user.getFirstName(), ((User) userInList.get(0)).getFirstName());
assertEquals(user.getUuid(), ((User) userInList.get(0)).getUuid());
// FOR EXTSOURCE
ExtSource extSource = new ExtSource(11, null, textMismatch);
List<PerunBean> extSourceInList = AuditParser.parseLog(extSource.serializeToString());
assertEquals(extSource.toString(), ((ExtSource) extSourceInList.get(0)).toString());
assertEquals(extSource.getName(), ((ExtSource) extSourceInList.get(0)).getName());
// FOR USEREXTSOURCE
UserExtSource userExtSource1 = new UserExtSource(15, extSource, null, 8, 15);
UserExtSource userExtSource2 = new UserExtSource(15, null, textMismatch, 8, 15);
List<PerunBean> userExtSource1InList = AuditParser.parseLog(userExtSource1.serializeToString());
List<PerunBean> userExtSource2InList = AuditParser.parseLog(userExtSource2.serializeToString());
assertEquals(userExtSource1.toString(), ((UserExtSource) userExtSource1InList.get(0)).toString());
assertEquals(userExtSource2.toString(), ((UserExtSource) userExtSource2InList.get(0)).toString());
assertEquals(userExtSource1.getLogin(), ((UserExtSource) userExtSource1InList.get(0)).getLogin());
assertEquals(userExtSource2.getExtSource(), ((UserExtSource) userExtSource2InList.get(0)).getExtSource());
// FOR VO (VO MUST HAVE ALL ATTRIBUTE NOT NULL)
Vo vo = new Vo(18, textMismatch, textMismatch);
List<PerunBean> voInList = AuditParser.parseLog(vo.serializeToString());
assertEquals(vo.toString(), ((Vo) voInList.get(0)).toString());
assertEquals(vo.getName(), ((Vo) voInList.get(0)).getName());
// FOR FACILITY
Facility facility = new Facility(15, null);
List<PerunBean> facilityInList = AuditParser.parseLog(facility.serializeToString());
assertEquals(facility.toString(), ((Facility) facilityInList.get(0)).toString());
assertEquals(facility.getName(), ((Facility) facility).getName());
// FOR RESOURCE
Resource resource = new Resource(15, textMismatch, null, 10, 10);
resource.setUuid(UUID.randomUUID());
List<PerunBean> resourceInList = AuditParser.parseLog(resource.serializeToString());
assertEquals(resource.toString(), ((Resource) resourceInList.get(0)).toString());
assertEquals(resource.getDescription(), ((Resource) resourceInList.get(0)).getDescription());
assertEquals(resource.getUuid(), ((Resource) resourceInList.get(0)).getUuid());
// FOR GROUP
Group group = new Group(textMismatch, null);
group.setId(15);
group.setUuid(UUID.randomUUID());
group.setParentGroupId(320);
Group group2 = new Group(textMismatch, null);
group2.setId(36);
group2.setParentGroupId(null);
List<PerunBean> groupInList = AuditParser.parseLog(group.serializeToString());
List<PerunBean> groupInList2 = AuditParser.parseLog(group2.serializeToString());
assertEquals(group.toString(), ((Group) groupInList.get(0)).toString());
assertEquals(group.getDescription(), ((Group) groupInList.get(0)).getDescription());
assertEquals(group.getUuid(), ((Group) groupInList.get(0)).getUuid());
assertEquals(group2.toString(), ((Group) groupInList2.get(0)).toString());
assertEquals(group2.getParentGroupId(), ((Group) groupInList2.get(0)).getParentGroupId());
// FOR RESOURCE TAG
List<PerunBean> resourceTagInList1 = AuditParser.parseLog(resourceTag1.serializeToString());
List<PerunBean> resourceTagInList2 = AuditParser.parseLog(resourceTag2.serializeToString());
assertEquals(resourceTag1.toString(), ((ResourceTag) resourceTagInList1.get(0)).toString());
assertEquals(resourceTag1.getTagName(), ((ResourceTag) resourceTagInList1.get(0)).getTagName());
assertEquals(resourceTag2.toString(), ((ResourceTag) resourceTagInList2.get(0)).toString());
assertEquals(resourceTag2.getTagName(), ((ResourceTag) resourceTagInList2.get(0)).getTagName());
// FOR MEMBER
Member member = new Member(6, 8, 8, null);
member.setSourceGroupId(null);
List<PerunBean> memberInList = AuditParser.parseLog(member.serializeToString());
assertEquals(member.toString(), ((Member) memberInList.get(0)).toString());
assertEquals(member.getStatus(), ((Member) memberInList.get(0)).getStatus());
// FOR DESTINATION
Destination destination = new Destination(7, null, textMismatch);
List<PerunBean> destinationInList = AuditParser.parseLog(destination.serializeToString());
assertEquals(destination.toString(), ((Destination) destinationInList.get(0)).toString());
assertEquals(destination.getDestination(), ((Destination) destinationInList.get(0)).getDestination());
// FOR HOST
Host host = new Host(5, null);
List<PerunBean> hostInList = AuditParser.parseLog(host.serializeToString());
assertEquals(host.toString(), ((Host) hostInList.get(0)).toString());
assertEquals(host.getHostname(), ((Host) hostInList.get(0)).getHostname());
// FOR OWNER
Owner owner = new Owner(5, null, textMismatch, OwnerType.administrative);
List<PerunBean> ownerInList = AuditParser.parseLog(owner.serializeToString());
assertEquals(owner.toString(), ((Owner) ownerInList.get(0)).toString());
assertEquals(owner.getName(), ((Owner) ownerInList.get(0)).getName());
// FOR SERVICE
Service service = new Service(8, null, null);
List<PerunBean> serviceInList = AuditParser.parseLog(service.serializeToString());
assertEquals(service.toString(), ((Service) serviceInList.get(0)).toString());
assertEquals(service.getName(), ((Service) serviceInList.get(0)).getName());
assertEquals(service.getDescription(), ((Service) serviceInList.get(0)).getDescription());
assertEquals(service.getDelay(), ((Service) serviceInList.get(0)).getDelay());
assertEquals(service.getRecurrence(), ((Service) serviceInList.get(0)).getRecurrence());
assertEquals(service.isEnabled(), ((Service) serviceInList.get(0)).isEnabled());
assertEquals(service.getScript(), ((Service) serviceInList.get(0)).getScript());
// FOR ATTRIBUTE DEFINITION
AttributeDefinition attributeDefinition1 = new AttributeDefinition(getAttributeDefinition1());
AttributeDefinition attributeDefinition2 = new AttributeDefinition(getAttributeDefinition2());
AttributeDefinition attributeDefinition3 = new AttributeDefinition(getAttributeDefinition3());
AttributeDefinition attributeDefinition4 = new AttributeDefinition(getAttributeDefinition4());
attributeDefinition1.setType(null);
attributeDefinition1.setDescription(null);
attributeDefinition1.setFriendlyName(null);
attributeDefinition1.setNamespace(null);
List<PerunBean> attributeDefinition1InList = AuditParser.parseLog(attributeDefinition1.serializeToString());
assertEquals(attributeDefinition1.toString(), ((AttributeDefinition) attributeDefinition1InList.get(0)).toString());
assertEquals(attributeDefinition1.getNamespace(), ((AttributeDefinition) attributeDefinition1InList.get(0)).getNamespace());
// FOR ATTRIBUTE
Attribute attribute1 = new Attribute(getAttributeDefinition1());
Attribute attribute2 = new Attribute(getAttributeDefinition2());
Attribute attribute3 = new Attribute(getAttributeDefinition3());
Attribute attribute4 = new Attribute(getAttributeDefinition4());
Attribute attribute5 = new Attribute(getAttributeDefinition3());
Attribute attribute6 = new Attribute(getAttributeDefinition4());
attribute5.setValue(null);
attribute6.setValue(null);
attribute1.setValue(null);
attribute2.setValue(null);
attribute3.setValue(new ArrayList<String>(Arrays.asList(new String[] { "a", null, null })));
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("a", null);
map.put(null, "d");
attribute4.setValue(map);
List<PerunBean> attribute1InList = AuditParser.parseLog(attribute1.serializeToString());
List<PerunBean> attribute2InList = AuditParser.parseLog(attribute2.serializeToString());
List<PerunBean> attribute3InList = AuditParser.parseLog(attribute3.serializeToString());
List<PerunBean> attribute4InList = AuditParser.parseLog(attribute4.serializeToString());
List<PerunBean> attribute5InList = AuditParser.parseLog(attribute5.serializeToString());
List<PerunBean> attribute6InList = AuditParser.parseLog(attribute6.serializeToString());
assertEquals(attribute1.toString(), ((Attribute) attribute1InList.get(0)).toString());
assertEquals(attribute2.toString(), ((Attribute) attribute2InList.get(0)).toString());
assertEquals(attribute3.toString(), ((Attribute) attribute3InList.get(0)).toString());
assertEquals(attribute4.toString(), ((Attribute) attribute4InList.get(0)).toString());
assertEquals(attribute5.toString(), ((Attribute) attribute5InList.get(0)).toString());
assertEquals(attribute6.toString(), ((Attribute) attribute6InList.get(0)).toString());
assertEquals(attribute3.getValue(), ((Attribute) attribute3InList.get(0)).getValue());
assertEquals(attribute4.getValue(), ((Attribute) attribute4InList.get(0)).getValue());
assertEquals(attribute5.getValue(), ((Attribute) attribute5InList.get(0)).getValue());
assertEquals(attribute6.getValue(), ((Attribute) attribute6InList.get(0)).getValue());
// FOR CANDIDATE
Map<String, String> attributesMap1 = new HashMap<String, String>();
attributesMap1.put("test1", null);
attributesMap1.put(null, null);
Candidate candidate1 = new Candidate(userExtSource1, attributesMap1);
Candidate candidate2 = new Candidate();
candidate2.setUserExtSource(null);
candidate2.setAttributes(null);
candidate1.setId(5);
candidate2.setId(6);
candidate1.setAdditionalUserExtSources(null);
List<UserExtSource> userExtSources = new ArrayList<UserExtSource>();
userExtSources.add(userExtSource1);
userExtSources.add(userExtSource2);
candidate2.setAdditionalUserExtSources(userExtSources);
List<PerunBean> candidate1InList = AuditParser.parseLog(candidate1.serializeToString());
List<PerunBean> candidate2InList = AuditParser.parseLog(candidate2.serializeToString());
assertEquals(candidate1.toString(), ((Candidate) candidate1InList.get(0)).toString());
assertEquals(candidate2.toString(), ((Candidate) candidate2InList.get(0)).toString());
assertEquals(candidate1.getAttributes(), ((Candidate) candidate1InList.get(0)).getAttributes());
assertEquals(candidate2.getAttributes(), ((Candidate) candidate2InList.get(0)).getAttributes());
// FOR SECURITY TEAM
SecurityTeam securityTeam = new SecurityTeam(18, textMismatch, textMismatch);
List<PerunBean> scsInList = AuditParser.parseLog(securityTeam.serializeToString());
assertEquals(securityTeam.toString(), ((SecurityTeam) scsInList.get(0)).toString());
assertEquals(securityTeam.getName(), ((SecurityTeam) scsInList.get(0)).getName());
assertEquals(securityTeam.getDescription(), ((SecurityTeam) scsInList.get(0)).getDescription());
// FOR TASK RESULT
List<PerunBean> trList = AuditParser.parseLog(taskResult1.serializeToString());
TaskResult taskResult2 = (TaskResult) trList.get(0);
assertEquals(taskResult1.toString(), taskResult2.toString());
// FOR BAN ON RESOURCE
List<PerunBean> banOnResourceInList = AuditParser.parseLog(banOnResource1.serializeToString());
assertEquals(banOnResource1.toString(), ((BanOnResource) banOnResourceInList.get(0)).toString());
assertEquals(banOnResource1.getMemberId(), ((BanOnResource) banOnResourceInList.get(0)).getMemberId());
assertEquals(banOnResource1.getResourceId(), ((BanOnResource) banOnResourceInList.get(0)).getResourceId());
assertEquals(banOnResource1.getDescription(), ((BanOnResource) banOnResourceInList.get(0)).getDescription());
assertEquals(banOnResource1.getValidityTo(), ((BanOnResource) banOnResourceInList.get(0)).getValidityTo());
// FOR BAN ON FACILITY
List<PerunBean> banOnFacilityInList = AuditParser.parseLog(banOnFacility1.serializeToString());
assertEquals(banOnFacility1.toString(), ((BanOnFacility) banOnFacilityInList.get(0)).toString());
assertEquals(banOnFacility1.getUserId(), ((BanOnFacility) banOnFacilityInList.get(0)).getUserId());
assertEquals(banOnFacility1.getFacilityId(), ((BanOnFacility) banOnFacilityInList.get(0)).getFacilityId());
assertEquals(banOnFacility1.getDescription(), ((BanOnFacility) banOnFacilityInList.get(0)).getDescription());
assertEquals(banOnFacility1.getValidityTo(), ((BanOnFacility) banOnFacilityInList.get(0)).getValidityTo());
// FOR RICHMEMBER
RichMember richMember1 = new RichMember(null, member, null);
// List<UserExtSource> userExtSources = new ArrayList<UserExtSource>();
// userExtSources.add(userExtSource1);
// userExtSources.add(null);
// userExtSources.add(userExtSource2);
// RichMember richMember2 = new RichMember(null, member, userExtSources);
List<Attribute> listOfAttributes = new ArrayList<Attribute>();
listOfAttributes.add(attribute1);
listOfAttributes.add(attribute2);
listOfAttributes.add(attribute3);
listOfAttributes.add(attribute4);
listOfAttributes.add(attribute5);
// TODO: Same problem like with userExtSources, what about null between attributes? Not Supported Now!
// listOfAttributes.add(null);
listOfAttributes.add(attribute6);
RichMember richMember3 = new RichMember(null, member, null, listOfAttributes, listOfAttributes);
List<PerunBean> richMember1InList = AuditParser.parseLog(richMember1.serializeToString());
// TODO: What about null pointers between userExtSources? Not Supported yet
// List<PerunBean> richMember2InList = AuditParser.parseLog(richMember2.serializeToString());
List<PerunBean> richMember3InList = AuditParser.parseLog(richMember3.serializeToString());
assertEquals(richMember1.toString(), ((RichMember) richMember1InList.get(0)).toString());
assertEquals(richMember1.isSponsored(), ((RichMember) richMember1InList.get(0)).isSponsored());
// assertEquals(richMember2, ((RichMember) richMember2InList.get(0)));
assertEquals(richMember3.toString(), ((RichMember) richMember3InList.get(0)).toString());
assertEquals(richMember3.isSponsored(), ((RichMember) richMember3InList.get(0)).isSponsored());
assertEquals(richMember1.getUser(), ((RichMember) richMember1InList.get(0)).getUser());
assertEquals(richMember1.getUserExtSources(), ((RichMember) richMember1InList.get(0)).getUserExtSources());
// FOR RICHUSER
RichUser richUser1 = new RichUser(user, null, null);
richUser1.setUuid(UUID.randomUUID());
RichUser richUser2 = new RichUser(user, null, listOfAttributes);
List<PerunBean> richUserInList = AuditParser.parseLog(richUser.serializeToString());
List<PerunBean> richUser1InList = AuditParser.parseLog(richUser1.serializeToString());
List<PerunBean> richUser2InList = AuditParser.parseLog(richUser2.serializeToString());
assertEquals(richUser.toString(), ((RichUser) richUserInList.get(0)).toString());
assertEquals(richUser1.toString(), ((RichUser) richUser1InList.get(0)).toString());
assertEquals(richUser1.getUuid(), ((RichUser) richUser1InList.get(0)).getUuid());
assertEquals(richUser2.toString(), ((RichUser) richUser2InList.get(0)).toString());
// FOR RICHGROUP
RichGroup richGroup1 = new RichGroup(group, null);
richGroup1.setUuid(UUID.randomUUID());
List<PerunBean> richGroupInList = AuditParser.parseLog(richGroup.serializeToString());
List<PerunBean> richGroup1InList = AuditParser.parseLog(richGroup1.serializeToString());
assertEquals(richGroup.toString(), ((RichGroup) richGroupInList.get(0)).toString());
assertEquals(richGroup1.toString(), ((RichGroup) richGroup1InList.get(0)).toString());
assertEquals(richGroup1.getUuid(), ((RichGroup) richGroup1InList.get(0)).getUuid());
// FOR RICHFACILITY
RichFacility richFacility1 = new RichFacility(facility, null);
List<Owner> owners = new ArrayList<Owner>();
owners.add(owner);
owners.add(owner1);
owners.add(owner2);
RichFacility richFacility2 = new RichFacility(facility, owners);
List<PerunBean> richFacility1InList = AuditParser.parseLog(richFacility1.serializeToString());
List<PerunBean> richFacility2InList = AuditParser.parseLog(richFacility2.serializeToString());
assertEquals(richFacility1.toString(), ((RichFacility) richFacility1InList.get(0)).toString());
assertEquals(richFacility2.toString(), ((RichFacility) richFacility2InList.get(0)).toString());
// FOR RICHRESOURCE
RichResource richResource = new RichResource(resource);
richResource.setFacility(null);
richResource.setVo(null);
richResource.addResourceTag(resourceTag1);
richResource.setUuid(UUID.randomUUID());
List<PerunBean> richResourceInList = AuditParser.parseLog(richResource.serializeToString());
assertEquals(richResource.toString(), ((RichResource) richResourceInList.get(0)).toString());
assertEquals(richResource.getFacility(), ((RichResource) richResourceInList.get(0)).getFacility());
assertEquals(richResource.getUuid(), ((RichResource) richResourceInList.get(0)).getUuid());
// FOR RICHDESTINATION
RichDestination richDestination = new RichDestination(destination, null, null);
List<PerunBean> richDestinationInList = AuditParser.parseLog(richDestination.serializeToString());
assertEquals(richDestination.toString(), ((RichDestination) richDestinationInList.get(0)).toString());
assertEquals(richDestination.getFacility(), ((RichDestination) richDestinationInList.get(0)).getFacility());
// FOR AUTHORSHIP
Authorship authorship1 = new Authorship();
authorship1.setId(1);
authorship1.setPublicationId(3);
authorship1.setUserId(18);
authorship1.setCreatedBy(textMismatch);
authorship1.setCreatedDate(new Date());
authorship1.setCreatedByUid(10);
Authorship authorship2 = new Authorship();
authorship2.setId(1);
authorship2.setPublicationId(3);
authorship2.setUserId(18);
authorship2.setCreatedBy(null);
authorship2.setCreatedDate(null);
authorship2.setCreatedByUid(0);
List<PerunBean> authorship1InList = AuditParser.parseLog(authorship1.serializeToString());
List<PerunBean> authorship2InList = AuditParser.parseLog(authorship2.serializeToString());
assertEquals(authorship1.toString(), ((Authorship) authorship1InList.get(0)).toString());
assertEquals(authorship2.toString(), ((Authorship) authorship2InList.get(0)).toString());
}
use of cz.metacentrum.perun.taskslib.model.TaskResult 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.taskslib.model.TaskResult in project perun by CESNET.
the class TaskResultDaoTest method testClearOldTaskResult.
@Test
public void testClearOldTaskResult() throws InternalErrorException, PrivilegeException, ServiceExistsException, OwnerNotExistsException, FacilityExistsException, ServiceNotExistsException, FacilityNotExistsException, DestinationAlreadyAssignedException, WrongPatternException {
System.out.println("TaskResultDao.clearOld");
Owner testOwner = new Owner();
testOwner.setContact("Call me");
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setType(OwnerType.technical);
testOwner = ownersManager.createOwner(perunSession, testOwner);
Service testService = new Service();
testService.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
testService = servicesManager.createService(perunSession, testService);
Service testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService2 = servicesManager.createService(perunSession, testService2);
Facility facility = new Facility();
facility.setName("Facility 1-" + Long.toHexString(System.currentTimeMillis()));
facility.setDescription("Description");
facility = facilitiesManager.createFacility(perunSession, facility);
Facility facility2 = new Facility();
facility2.setName("Facility 2-" + Long.toHexString(System.currentTimeMillis()));
facility2.setDescription("Description");
facility2 = facilitiesManager.createFacility(perunSession, facility2);
ExecService testExecService = new ExecService();
testExecService.setDefaultDelay(1);
testExecService.setDefaultRecurrence(1);
testExecService.setEnabled(true);
testExecService.setService(testService);
testExecService.setScript("serviceGenerate.bash");
testExecService.setExecServiceType(ExecService.ExecServiceType.GENERATE);
testExecService.setId(execServiceDao.insertExecService(testExecService));
ExecService testExecService2 = new ExecService();
testExecService2.setDefaultDelay(1);
testExecService2.setDefaultRecurrence(1);
testExecService2.setEnabled(true);
testExecService2.setService(testService2);
testExecService2.setScript("serviceGenerate.bash");
testExecService2.setExecServiceType(ExecService.ExecServiceType.GENERATE);
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
Destination destination1 = new Destination();
destination1.setDestination("Destination-1-" + Long.toHexString(System.currentTimeMillis()));
destination1.setType(Destination.DESTINATIONEMAILTYPE);
destination1 = servicesManager.addDestination(perunSession, testService, facility, destination1);
Destination destination2 = new Destination();
destination2.setDestination("Destination-2-" + Long.toHexString(System.currentTimeMillis()));
destination2.setType(Destination.DESTINATIONEMAILTYPE);
destination2 = servicesManager.addDestination(perunSession, testService, facility, destination2);
Destination destination3 = new Destination();
destination3.setDestination("Destination-3-" + Long.toHexString(System.currentTimeMillis()));
destination3.setType(Destination.DESTINATIONEMAILTYPE);
destination3 = servicesManager.addDestination(perunSession, testService2, facility2, destination3);
Task testTask1 = new Task();
testTask1.setDelay(10);
testTask1.setExecService(testExecService);
testTask1.setFacility(facility);
testTask1.setRecurrence(10);
testTask1.setSchedule(new Date());
testTask1.setStatus(Task.TaskStatus.PROCESSING);
testTask1.setId(taskDao.scheduleNewTask(testTask1, virtualEngineID));
Task testTask2 = new Task();
testTask2.setDelay(10);
testTask2.setExecService(testExecService2);
testTask2.setFacility(facility2);
testTask2.setRecurrence(10);
testTask2.setSchedule(new Date());
testTask2.setStatus(Task.TaskStatus.PROCESSING);
testTask2.setId(taskDao.scheduleNewTask(testTask2, virtualEngineID));
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -2);
TaskResult taskResult = new TaskResult();
taskResult.setDestinationId(destination1.getId());
taskResult.setErrorMessage("error message");
taskResult.setReturnCode(0);
taskResult.setStandardMessage("std message");
taskResult.setStatus(TaskResult.TaskResultStatus.DONE);
taskResult.setTaskId(testTask1.getId());
taskResult.setTimestamp(cal.getTime());
taskResult.setService(testService);
taskResult.setId(taskResultDao.insertNewTaskResult(taskResult, virtualEngineID));
TaskResult taskResult2 = new TaskResult();
taskResult2.setDestinationId(destination3.getId());
taskResult2.setErrorMessage("error message");
taskResult2.setReturnCode(0);
taskResult2.setStandardMessage("std message");
taskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
taskResult2.setTaskId(testTask2.getId());
taskResult2.setTimestamp(cal.getTime());
taskResult2.setService(testService2);
taskResult2.setId(taskResultDao.insertNewTaskResult(taskResult2, virtualEngineID));
cal.add(Calendar.DATE, -5);
TaskResult oldTaskResult = new TaskResult();
oldTaskResult.setDestinationId(destination1.getId());
oldTaskResult.setErrorMessage("error message");
oldTaskResult.setReturnCode(0);
oldTaskResult.setStandardMessage("std message");
oldTaskResult.setStatus(TaskResult.TaskResultStatus.DONE);
oldTaskResult.setTaskId(testTask1.getId());
oldTaskResult.setTimestamp(cal.getTime());
oldTaskResult.setService(testService);
oldTaskResult.setId(taskResultDao.insertNewTaskResult(oldTaskResult, virtualEngineID));
TaskResult oldTaskResult2 = new TaskResult();
oldTaskResult2.setDestinationId(destination3.getId());
oldTaskResult2.setErrorMessage("error message");
oldTaskResult2.setReturnCode(0);
oldTaskResult2.setStandardMessage("std message");
oldTaskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
oldTaskResult2.setTaskId(testTask2.getId());
oldTaskResult2.setTimestamp(cal.getTime());
oldTaskResult2.setService(testService2);
oldTaskResult2.setId(taskResultDao.insertNewTaskResult(oldTaskResult2, virtualEngineID));
TaskResult uniqueTaskResult = new TaskResult();
uniqueTaskResult.setDestinationId(destination2.getId());
uniqueTaskResult.setErrorMessage("error message");
uniqueTaskResult.setReturnCode(0);
uniqueTaskResult.setStandardMessage("std message");
uniqueTaskResult.setStatus(TaskResult.TaskResultStatus.DONE);
uniqueTaskResult.setTaskId(testTask1.getId());
uniqueTaskResult.setTimestamp(cal.getTime());
uniqueTaskResult.setService(testService);
uniqueTaskResult.setId(taskResultDao.insertNewTaskResult(uniqueTaskResult, virtualEngineID));
TaskResult uniqueTaskResult2 = new TaskResult();
uniqueTaskResult2.setDestinationId(destination2.getId());
uniqueTaskResult2.setErrorMessage("error message");
uniqueTaskResult2.setReturnCode(0);
uniqueTaskResult2.setStandardMessage("std message");
uniqueTaskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
uniqueTaskResult2.setTaskId(testTask2.getId());
uniqueTaskResult2.setTimestamp(cal.getTime());
uniqueTaskResult2.setService(testService2);
uniqueTaskResult2.setId(taskResultDao.insertNewTaskResult(uniqueTaskResult2, virtualEngineID));
TaskResult foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
TaskResult foundTaskResult2 = taskResultDao.getTaskResultById(oldTaskResult.getId());
TaskResult foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
TaskResult foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
TaskResult foundTaskResult5 = taskResultDao.getTaskResultById(oldTaskResult2.getId());
TaskResult foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(oldTaskResult, foundTaskResult2);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(oldTaskResult2, foundTaskResult5);
assertEquals(uniqueTaskResult2, foundTaskResult6);
taskResultDao.clearOld(virtualEngineID, 6);
foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(uniqueTaskResult2, foundTaskResult6);
try {
taskResultDao.getTaskResultById(oldTaskResult.getId());
fail("TaskResult " + taskResult + " should not have been found");
} catch (EmptyResultDataAccessException e) {
}
try {
taskResultDao.getTaskResultById(oldTaskResult2.getId());
fail("TaskResult " + taskResult2 + " should not have been found");
} catch (EmptyResultDataAccessException e) {
}
taskResultDao.clearOld(virtualEngineID, 1);
foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(uniqueTaskResult2, foundTaskResult6);
}
use of cz.metacentrum.perun.taskslib.model.TaskResult in project perun by CESNET.
the class PropagationMaintainerImpl method onTaskDestinationComplete.
@Override
public void onTaskDestinationComplete(int clientID, String string) {
if (string == null || string.isEmpty()) {
log.error("Could not parse taskresult message from engine " + clientID);
return;
}
try {
List<PerunBean> listOfBeans = AuditParser.parseLog(string);
if (!listOfBeans.isEmpty()) {
TaskResult taskResult = (TaskResult) listOfBeans.get(0);
resultManager.insertNewTaskResult(taskResult, clientID);
} else {
log.error("No TaskResult bean found in message {} from engine {}", string, clientID);
}
} catch (Exception e) {
log.error("Could not save taskresult message {} from engine " + clientID, string);
log.debug("Error storing taskresult message: " + e.getMessage());
}
}
Aggregations