use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class GeneralServiceManagerImpl method insertExecService.
@Override
public int insertExecService(PerunSession perunSession, ExecService execService) throws InternalErrorException, PrivilegeException, ServiceExistsException {
Service service = null;
try {
service = servicesManager.getServiceByName(perunSession, execService.getService().getName());
} catch (ServiceNotExistsException e) {
service = servicesManager.createService(perunSession, execService.getService());
}
execService.setService(service);
return execServiceDao.insertExecService(execService);
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ExecServiceDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
try {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
} catch (InternalErrorException e) {
log.error(e.toString());
}
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setType(OwnerType.technical);
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ExecServiceDenialDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setType(OwnerType.technical);
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
// Testing Destination #1
testDestinationId1 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId1, "test.destination." + testDestinationId1);
// Testing Destination #2
testDestinationId2 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId2, "test.destination." + testDestinationId2);
// Testing Facility #1
testFacilityId1 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId1, "Cluster_" + testFacilityId1);
// Testing Facility #2
testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
// Test ExecService #1 (Parent:testService1)
testExecService1 = new ExecService();
testExecService1.setDefaultDelay(1);
testExecService1.setDefaultRecurrence(1);
testExecService1.setEnabled(true);
testExecService1.setService(testService1);
testExecService1.setScript("/hellish/test/script");
testExecService1.setExecServiceType(ExecServiceType.GENERATE);
try {
testExecService1.setId(execServiceDao.insertExecService(testExecService1));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #2 (Parent:testService1)
testExecService2 = new ExecService();
testExecService2.setDefaultDelay(2);
testExecService2.setDefaultRecurrence(2);
testExecService2.setEnabled(true);
testExecService2.setService(testService2);
testExecService2.setScript("/hellish/test/script2");
testExecService2.setExecServiceType(ExecServiceType.SEND);
try {
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class TasksManagerBlImpl method getFacilityServicesState.
@Override
public List<ServiceState> getFacilityServicesState(PerunSession sess, Facility facility) {
Map<Service, ServiceState> serviceStates = new HashMap<>();
// fill states for all services which are currently on facility
for (Service service : perun.getServicesManagerBl().getAssignedServices(sess, facility)) {
serviceStates.put(service, new ServiceState(service, facility));
serviceStates.get(service).setBlockedOnFacility(getServicesManagerBl().isServiceBlockedOnFacility(service, facility));
// service has destination on facility
serviceStates.get(service).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, service, facility).isEmpty());
}
// fill states for all tasks on facility
List<Task> tasks = getTasksManagerImpl().listAllTasksForFacility(facility.getId());
for (Task task : tasks) {
Service taskService = task.getService();
ServiceState serviceState = serviceStates.get(taskService);
if (serviceState == null) {
serviceState = new ServiceState(taskService, facility);
serviceStates.put(taskService, serviceState);
// fill destinations if service was not assigned
serviceStates.get(taskService).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, taskService, facility).isEmpty());
}
// fill service state
serviceState.setTask(task);
serviceStates.get(taskService).setBlockedOnFacility(getServicesManagerBl().isServiceBlockedOnFacility(task.getService(), facility));
}
return new ArrayList<>(serviceStates.values());
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ResourcesManagerBlImpl method assignServices.
@Override
public void assignServices(PerunSession sess, Resource resource, List<Service> services) throws ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
for (Service service : services) {
getResourcesManagerImpl().assignService(sess, resource, service);
getPerunBl().getAuditer().log(sess, new ServiceAssignedToResource(service, resource));
}
boolean requiresAttributes = services.stream().anyMatch(s -> !getPerunBl().getAttributesManagerBl().getRequiredAttributesDefinition(sess, s).isEmpty());
if (!requiresAttributes) {
// there are new no attributes to check or add
return;
}
try {
fillAndSetRequiredAttributesForGroups(sess, services, resource);
checkSemanticsOfFacilityAndResourceRequiredAttributes(sess, resource);
updateAllRequiredAttributesForAllowedMembers(sess, resource, services);
} catch (WrongAttributeAssignmentException | GroupResourceMismatchException | MemberResourceMismatchException | AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
Aggregations