Search in sources :

Example 61 with Facility

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

the class ServicesManagerEntryIntegrationTest method removeDestinationWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void removeDestinationWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "removeDestinationWhenFacilityNotExists");
    service = setUpService();
    destination = setUpDestination();
    perun.getServicesManager().removeDestination(sess, service, new Facility(), destination);
// shouldn't find facility
}
Also used : Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 62 with Facility

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

the class SecurityTeamsManagerEntryIntegrationTest method testGetBlacklistByFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void testGetBlacklistByFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "testGetBlacklistByFacilityNotExists");
    setUpSecurityTeams();
    setUpUsers();
    setUpFacilities();
    setUpBlacklists();
    Facility facility = new Facility(0, "facility");
    securityTeamsManagerEntry.getBlacklist(sess, facility);
}
Also used : Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 63 with Facility

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

the class urn_perun_user_facility_attribute_def_virt_defaultUnixGIDTest method getValueDefaultUGidIsSetTest.

@Test
public void getValueDefaultUGidIsSetTest() throws Exception {
    System.out.println("urn_perun_user_facility_attribute_def_virt_defaultUnixGID.getValueDefaultUGidIsSetTest ()");
    //setup
    dDefaultUnixGid.setValue(123);
    //phase one
    //UF:D:DefaultUnixGid attr
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), any(User.class), eq(AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":defaultUnixGID"))).thenReturn(dDefaultUnixGid);
    //phase two
    //namespace String
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), eq(AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace")).getValue()).thenReturn(namespace);
    //prefferedUnixGroupName attr
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(User.class), eq(AttributesManager.NS_USER_ATTR_DEF + ":preferredUnixGroupName-namespace:" + namespace))).thenReturn(prefferedUnixGroupName);
    //allowedResource list<resource>
    when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSessionImpl.class), any(Facility.class), any(User.class))).thenReturn(allowedResource);
    //R:D:unixGroupName-namespace:namespace string
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Resource.class), eq(AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGroupName-namespace:" + namespace)).getValue()).thenReturn(resourceGroupName);
    //getMemberByUser list<members>
    when(session.getPerunBl().getMembersManagerBl().getMembersByUser(any(PerunSessionImpl.class), any(User.class))).thenReturn(memberByUser);
    //getAssignedGroupsToResource list<group>
    when(session.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(any(PerunSessionImpl.class), any(Resource.class))).thenReturn(assignedGroupsToResource);
    //getGroupMembers list<members>
    when(session.getPerunBl().getGroupsManagerBl().getGroupMembers(any(PerunSessionImpl.class), any(Group.class))).thenReturn(groupMembers);
    //G:D:unixGroupName-namespace:namespace string
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Group.class), eq(AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + namespace)).getValue()).thenReturn(groupGroupName);
    //R:D:unixGID-namespace:namespace int
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Resource.class), eq(AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespace)).getValue()).thenReturn(resourceUnixGID);
    //G:D:unixGID-namespace:namespace int
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Group.class), eq(AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + namespace)).getValue()).thenReturn(groupUnixGID);
    //phase three
    //UF:D:basicDefaultGID attr
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSessionImpl.class), any(Facility.class), any(User.class), eq(AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":basicDefaultGID"))).thenReturn(basicDefaultGID);
    Attribute testAttr = classInstance.getAttributeValue(session, facility, user, attrDef);
    assertEquals(testAttr, dDefaultUnixGid);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Test(org.junit.Test)

Example 64 with Facility

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

the class urn_perun_user_facility_attribute_def_virt_shellTest method setUp.

@Before
public void setUp() {
    classInstance = new urn_perun_user_facility_attribute_def_virt_shell();
    session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
    preffered = new Attribute();
    defDefShell = new Attribute();
    facilityShell = new Attribute();
    resourceShell = new ArrayList();
    listOfMntPts = new ArrayList<String>();
    for (int i = 0; i < 5; i++) listOfMntPts.add("/mnt/bash" + i);
    preffered.setValue(new ArrayList(listOfMntPts));
    listOfMntPts.clear();
    listOfMntPts.add("/mnt/bash2");
    facilityShell.setValue(listOfMntPts);
    resourceShell.addAll(listOfMntPts);
    user = new User();
    facility = new Facility();
    resource = new Resource();
    resource.setName("myResource");
    resource.setDescription("desc");
    resource1 = new Resource();
    resource1.setId(1);
    resource1.setName("myResource");
    resource1.setDescription("desc");
    resourceList = new ArrayList<Resource>();
    resourceList.add(resource1);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Before(org.junit.Before)

Example 65 with Facility

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

the class PropagationMaintainerImpl method rescheduleErrorTasks.

private void rescheduleErrorTasks() {
    log.info("I am gonna list tasks in ERROR and reschedule if necessary...");
    for (Task task : schedulingPool.getErrorTasks()) {
        if (task.getEndTime() == null) {
            log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1.");
            // getDelay is in minutes, therefore we multiply it with 60*1000
            Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
            task.setEndTime(endTime);
        }
        int howManyMinutesAgo = (int) (System.currentTimeMillis() - task.getEndTime().getTime()) / 1000 / 60;
        if (howManyMinutesAgo < 0) {
            log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task appears to have ended in future.");
            Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
            task.setEndTime(endTime);
            howManyMinutesAgo = task.getDelay() + 1;
        }
        log.info("TASK [" + task + "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
        // XXX - apparently this is not what the authors had in mind,
        // commented out
        // check and set recurrence
        // int recurrence = task.getRecurrence() - 1;
        // if(recurrence < 0) {
        // // no more retries, sorry
        // log.info("TASK [ " + task +
        // "] in ERROR state has no more retries, bailing out.");
        // continue;
        // }
        // task.setRecurrence(recurrence);
        // If DELAY time has passed, we reschedule...
        int recurrence = task.getRecurrence() + 1;
        if (recurrence > task.getExecService().getDefaultRecurrence() && howManyMinutesAgo < 60 * 12 && !task.isSourceUpdated()) {
            log.info("TASK [ " + task + "] in ERROR state has no more retries, bailing out.");
        } else if (howManyMinutesAgo >= recurrence * task.getDelay() || task.isSourceUpdated()) {
            // check if service is still assigned on facility
            try {
                List<Service> assignedServices = perun.getServicesManager().getAssignedServices(perunSession, task.getFacility());
                if (assignedServices.contains(task.getExecService().getService())) {
                    ExecService execService = task.getExecService();
                    Facility facility = task.getFacility();
                    if (recurrence > execService.getDefaultRecurrence()) {
                        // this ERROR task is rescheduled for being here too long
                        task.setRecurrence(0);
                        task.setDestinations(null);
                        log.info("TASK id " + task.getId() + " is in ERROR state long enough, ");
                    }
                    task.setRecurrence(recurrence);
                    log.info("TASK [" + task + "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID " + execService.getId() + ", new Date(System.currentTimeMillis()), facility:ID " + facility.getId() + ");");
                    // taskScheduler.propagateService(task, new
                    // Date(System.currentTimeMillis()));
                    taskScheduler.scheduleTask(task);
                    log.info("TASK [" + task + "] in ERROR state has been rescheduled.");
                    // Also (to be sure) reschedule all Tasks that depend on
                    // this Task
                    //
                    // While engine starts in state GEN = ERROR, SEND = DONE
                    // => GEN will be rescheduled but without this SEND will
                    // never be propagated
                    List<ExecService> dependantServices = dependenciesResolver.listDependantServices(execService);
                    for (ExecService dependantService : dependantServices) {
                        Task dependantTask = schedulingPool.getTask(dependantService, facility);
                        if (dependantTask == null) {
                            dependantTask = new Task();
                            dependantTask.setExecService(dependantService);
                            dependantTask.setFacility(facility);
                            dependantTask.setRecurrence(dependantService.getDefaultRecurrence());
                            schedulingPool.addToPool(dependantTask, schedulingPool.getQueueForTask(task));
                            taskScheduler.scheduleTask(dependantTask);
                            log.info("{} was rescheduled because it depends on {}", dependantTask, task);
                        }
                    }
                } else {
                    // delete this tasks (SEND and GEN) because service is
                    // no longer assigned to facility
                    schedulingPool.removeTask(task);
                    log.warn("Removed TASK {} from database, beacuse service is no longer assigned to this facility.", task.toString());
                }
            } catch (FacilityNotExistsException e) {
                schedulingPool.removeTask(task);
                log.error("Removed TASK {} from database, facility no longer exists.", task.getId());
            } catch (InternalErrorException e) {
                log.error("{}", e);
            } catch (PrivilegeException e) {
                log.error("Consistency error. {}", e);
            }
        }
    }
/*
		 * Original implementation:
		 *
		 * //TODO: Take into account Recurrence! for (Task task :
		 * taskManager.listAllTasksInState(TaskStatus.ERROR,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")))) {
		 * if (task.getEndTime() == null) { log.error(
		 * "RECOVERY FROM INCONSISTATE STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1."
		 * ); // getDelay is in minutes, therefore we multiply it with 60*1000
		 * Date endTime = new Date(System.currentTimeMillis() -
		 * ((task.getDelay() + 1) * 60000)); task.setEndTime(endTime);
		 * taskManager.updateTask(task,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
		 * int howManyMinutesAgo = (int) (System.currentTimeMillis() -
		 * task.getEndTime().getTime()) / 1000 / 60; log.info("TASK [" + task +
		 * "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
		 * //If DELAY time has passed, we reschedule... if (howManyMinutesAgo >=
		 * task.getDelay()) { //check if service is still assigned on facility
		 * try { List<Service> assignedServices =
		 * Rpc.ServicesManager.getAssignedServices(engineManager.getRpcCaller(),
		 * task.getFacility());
		 * if(assignedServices.contains(task.getExecService().getService())) {
		 * try { taskManager.updateTask(task,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * ExecService execService = task.getExecService(); Facility facility =
		 * task.getFacility(); log.info("TASK [" + task +
		 * "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID "
		 * + execService.getId() +
		 * ", new Date(System.currentTimeMillis()), facility:ID " +
		 * facility.getId() + ");"); taskScheduler.propagateService(execService,
		 * new Date(System.currentTimeMillis()), facility); log.info("TASK [" +
		 * task + "] in ERROR state has been rescheduled.");
		 *
		 * //Also (to be sure) reschedule all execServices which depends on this
		 * exec service // //While engine starts in state GEN = ERROR, SEND =
		 * DONE => GEN will be rescheduled but without this SEND will never be
		 * propagated List<ExecService> dependentExecServices =
		 * Rpc.GeneralServiceManager
		 * .listExecServicesDependingOn(engineManager.getRpcCaller(),
		 * execService); if(dependentExecServices != null) { for(ExecService
		 * dependantExecService : dependentExecServices) {
		 * taskScheduler.propagateService(dependantExecService, new
		 * Date(System.currentTimeMillis()), facility);
		 * log.info("{} was rescheduled because it depends on {}",
		 * dependantExecService, execService); } }
		 *
		 * } catch (InternalErrorException e) { log.error(e.toString(), e); } }
		 * else { //delete this tasks (SEND and GEN) because service is no
		 * longer assigned to facility List<ExecService> execServicesGenAndSend
		 * =
		 * Rpc.GeneralServiceManager.listExecServices(engineManager.getRpcCaller
		 * (), task.getExecService().getService().getId()); for(ExecService
		 * execService : execServicesGenAndSend) { Task taskToDelete =
		 * taskManager.getTask(execService, task.getFacility(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * if(taskToDelete!= null) {
		 * resultManager.clearByTask(taskToDelete.getId(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * taskManager.removeTask(taskToDelete.getId(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
		 * } } } catch(PrivilegeException ex) {
		 * log.error("Consistency error. {}", ex); }
		 * catch(FacilityNotExistsException ex) {
		 * log.error("Consistency error - found task for non-existing facility. {}"
		 * , ex); } catch(ServiceNotExistsException ex) {
		 * log.error("Consistency error - found task for non-existing service. {}"
		 * , ex); } catch(InternalErrorException ex) { log.error("{}", ex); } }
		 * }
		 */
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ArrayList(java.util.ArrayList) List(java.util.List) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Date(java.util.Date)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)188 Test (org.junit.Test)95 User (cz.metacentrum.perun.core.api.User)81 Attribute (cz.metacentrum.perun.core.api.Attribute)75 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)61 Resource (cz.metacentrum.perun.core.api.Resource)52 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)51 ArrayList (java.util.ArrayList)48 Group (cz.metacentrum.perun.core.api.Group)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 Member (cz.metacentrum.perun.core.api.Member)22 PerunSession (cz.metacentrum.perun.core.api.PerunSession)20 RichFacility (cz.metacentrum.perun.core.api.RichFacility)20 Host (cz.metacentrum.perun.core.api.Host)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17 RichUser (cz.metacentrum.perun.core.api.RichUser)16 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Vo (cz.metacentrum.perun.core.api.Vo)13