Search in sources :

Example 1 with ServiceExistsException

use of cz.metacentrum.perun.core.api.exceptions.ServiceExistsException in project perun by CESNET.

the class GeneralServiceManagerImpl method createCompleteService.

@Override
@Transactional(rollbackFor = Exception.class)
public Service createCompleteService(PerunSession perunSession, String serviceName, String scriptPath, int defaultDelay, boolean enabled) throws InternalErrorException, PrivilegeException, ServiceExistsException {
    if (!AuthzResolver.isAuthorized(perunSession, Role.PERUNADMIN)) {
        throw new PrivilegeException(perunSession, "createCompleteService");
    }
    Service service = null;
    try {
        service = servicesManager.getServiceByName(perunSession, serviceName);
        if (service != null) {
            throw new ServiceExistsException(service);
        }
    } catch (ServiceNotExistsException e) {
        service = new Service();
        service.setName(serviceName);
        service = servicesManager.createService(perunSession, service);
    }
    ExecService genExecService = new ExecService();
    genExecService.setService(service);
    genExecService.setDefaultDelay(defaultDelay);
    genExecService.setEnabled(enabled);
    genExecService.setScript(scriptPath);
    genExecService.setExecServiceType(ExecServiceType.GENERATE);
    genExecService.setId(execServiceDao.insertExecService(genExecService));
    ExecService sendExecService = new ExecService();
    sendExecService.setService(service);
    sendExecService.setDefaultDelay(defaultDelay);
    sendExecService.setEnabled(enabled);
    sendExecService.setScript(scriptPath);
    sendExecService.setExecServiceType(ExecServiceType.SEND);
    sendExecService.setId(execServiceDao.insertExecService(sendExecService));
    this.createDependency(sendExecService, genExecService);
    return service;
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ServiceExistsException

use of cz.metacentrum.perun.core.api.exceptions.ServiceExistsException in project perun by CESNET.

the class ExecServiceDependencyDaoTest method beforeClass.

@Before
public void beforeClass() {
    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 = 0;
    try {
        newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
    } catch (InternalErrorException e) {
        log.error(e.toString(), e);
    }
    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()));
    try {
        testService1.setId(servicesManager.createService(perunSession, testService1).getId());
        testService2.setId(servicesManager.createService(perunSession, testService2).getId());
    } catch (InternalErrorException e) {
        log.error(e.toString());
    } catch (PrivilegeException e) {
        log.error(e.toString());
    } catch (ServiceExistsException e) {
        log.error(e.toString());
    }
    // 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(testService1);
    testExecService2.setScript("/hellish/test/script2");
    testExecService2.setExecServiceType(ExecServiceType.SEND);
    try {
        testExecService2.setId(execServiceDao.insertExecService(testExecService2));
    } catch (InternalErrorException e) {
        log.error(e.toString(), e);
    }
    // Test ExecService #3 (Parent:testService2)
    testExecService3 = new ExecService();
    testExecService3.setDefaultDelay(3);
    testExecService3.setDefaultRecurrence(3);
    testExecService3.setEnabled(true);
    testExecService3.setService(testService2);
    testExecService3.setScript("/hellish/test/script3");
    testExecService3.setExecServiceType(ExecServiceType.SEND);
    try {
        testExecService3.setId(execServiceDao.insertExecService(testExecService3));
    } catch (InternalErrorException e) {
        log.error(e.toString(), e);
    }
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Owner(cz.metacentrum.perun.core.api.Owner) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Before(org.junit.Before)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 ServiceExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceExistsException)2 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)2 Owner (cz.metacentrum.perun.core.api.Owner)1 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)1 Before (org.junit.Before)1 JdbcPerunTemplate (org.springframework.jdbc.core.JdbcPerunTemplate)1 Transactional (org.springframework.transaction.annotation.Transactional)1