Search in sources :

Example 6 with Service

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

the class FacilitiesManagerEntryIntegrationTest method addHostAndDestinationSameNameSameAdmin.

@Test
public void addHostAndDestinationSameNameSameAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostAndDestinationSameNameSameAdmin");
    // Initialize host, destination and service
    String hostName = "TestHost";
    Host hostOne = new Host(0, hostName);
    Destination destination = new Destination(0, hostName, Destination.DESTINATIONHOSTTYPE);
    Service service = new Service(0, "testService");
    ServicesManager servicesManagerEntry = perun.getServicesManager();
    service = servicesManagerEntry.createService(sess, service);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    // Set userOne as admin for both facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userOne);
    // Sets userOne as actor in this test with role facility admin for facility
    List<PerunBean> list = new ArrayList<PerunBean>();
    list.add(facility);
    list.add(secondFacility);
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, list);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds host to facility
    facilitiesManagerEntry.addHost(sess, hostOne, facility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, facility).size() == 1);
    // Adds destination with same name as host to facility
    servicesManagerEntry.addDestination(sess, service, facility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, facility).size() == 1);
    // Adds same host to second facility
    facilitiesManagerEntry.addHost(sess, hostOne, secondFacility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, secondFacility).size() == 1);
    // Adds destination with same name as host to secondFacility
    servicesManagerEntry.addDestination(sess, service, secondFacility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, secondFacility).size() == 1);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) PerunBean(cz.metacentrum.perun.core.api.PerunBean) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ServicesManager(cz.metacentrum.perun.core.api.ServicesManager) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Service(cz.metacentrum.perun.core.api.Service) Host(cz.metacentrum.perun.core.api.Host) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 7 with Service

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

the class FacilitiesManagerEntryIntegrationTest method getAssignedResourcesWithVoOrServiceFilter.

@Test
public void getAssignedResourcesWithVoOrServiceFilter() throws Exception {
    System.out.println(CLASS_NAME + "getAssignedResourcesWithVoOrServiceFilter");
    // Test that new method returns same data as old behavior
    Vo vo2 = new Vo(0, "facilityTestVo002", "facilityTestVo002");
    vo2 = perun.getVosManagerBl().createVo(sess, vo2);
    Member member11 = setUpMember(vo);
    Member member12 = setUpMember(vo);
    Member member21 = setUpMember(vo2);
    Member member22 = setUpMember(vo2);
    Resource resource1 = setUpResource(vo);
    Resource resource2 = setUpResource(vo2);
    Group group1 = setUpGroup(vo, member11);
    Group group2 = setUpGroup(vo2, member21);
    // make them not-allowed
    perun.getMembersManager().setStatus(sess, member12, Status.INVALID);
    perun.getMembersManager().setStatus(sess, member22, Status.DISABLED);
    perun.getGroupsManager().addMember(sess, group1, member12);
    perun.getGroupsManager().addMember(sess, group2, member22);
    perun.getResourcesManager().assignGroupToResource(sess, group1, resource1);
    perun.getResourcesManager().assignGroupToResource(sess, group2, resource2);
    // test new way - single select
    List<Member> members = perun.getFacilitiesManagerBl().getAllowedMembers(sess, facility);
    Assert.notNull(members);
    assertTrue(members.size() == 2);
    assertTrue(members.contains(member11));
    assertTrue(members.contains(member21));
    assertTrue(!members.contains(member12));
    assertTrue(!members.contains(member22));
    // check getting all
    List<Resource> resources = perun.getFacilitiesManager().getAssignedResources(sess, facility);
    Assert.notNull(resources);
    assertTrue(resources.size() == 2);
    assertTrue(resources.contains(resource1));
    assertTrue(resources.contains(resource2));
    // check getting by VO
    resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo, null);
    Assert.notNull(resources);
    assertTrue(resources.size() == 1);
    assertTrue(resources.contains(resource1));
    assertTrue(!resources.contains(resource2));
    Service service = new Service(0, "TestService01");
    service = perun.getServicesManager().createService(sess, service);
    perun.getResourcesManager().assignService(sess, resource1, service);
    // service should be only on 1 resource
    resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, null, service);
    Assert.notNull(resources);
    assertTrue(resources.size() == 1);
    assertTrue(resources.contains(resource1));
    assertTrue(!resources.contains(resource2));
    // vo-service should by only for 1 resource
    resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo, service);
    Assert.notNull(resources);
    assertTrue(resources.size() == 1);
    assertTrue(resources.contains(resource1));
    assertTrue(!resources.contains(resource2));
    // vo2-service shouldn't be assigned
    resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo2, service);
    Assert.notNull(resources);
    assertTrue(resources.isEmpty());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Service(cz.metacentrum.perun.core.api.Service) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 8 with Service

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

the class ServicesManagerEntryIntegrationTest method getHierarchicalDataWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void getHierarchicalDataWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getHierarchicalDataWhenServiceNotExists");
    facility = setUpFacility();
    perun.getServicesManager().getHierarchicalData(sess, new Service(), facility);
// shouldn't find service
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 9 with Service

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

the class ServicesManagerEntryIntegrationTest method getAssignedResourcesWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void getAssignedResourcesWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getAssignedResourcesWhenServiceNotExists");
    perun.getServicesManager().getAssignedResources(sess, new Service());
// shouldn't find service
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 10 with Service

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

the class ServicesManagerEntryIntegrationTest method addServiceToServicesPackageWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void addServiceToServicesPackageWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "addServiceToServicesPackageWhenServiceNotExists");
    ServicesPackage servicesPackage = new ServicesPackage();
    servicesPackage.setName("ServicesManagerTestSP");
    servicesPackage.setDescription("TestingPackage");
    perun.getServicesManager().createServicesPackage(sess, servicesPackage);
    perun.getServicesManager().addServiceToServicesPackage(sess, servicesPackage, new Service());
// shouldn't find services package
}
Also used : Service(cz.metacentrum.perun.core.api.Service) ServicesPackage(cz.metacentrum.perun.core.api.ServicesPackage) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)66 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)44 Test (org.junit.Test)44 ArrayList (java.util.ArrayList)11 Facility (cz.metacentrum.perun.core.api.Facility)10 Destination (cz.metacentrum.perun.core.api.Destination)9 Member (cz.metacentrum.perun.core.api.Member)8 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)8 User (cz.metacentrum.perun.core.api.User)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 Attribute (cz.metacentrum.perun.core.api.Attribute)5 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)5 Group (cz.metacentrum.perun.core.api.Group)5 Host (cz.metacentrum.perun.core.api.Host)5 Resource (cz.metacentrum.perun.core.api.Resource)5 RichDestination (cz.metacentrum.perun.core.api.RichDestination)5 RichUser (cz.metacentrum.perun.core.api.RichUser)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 PerunClient (cz.metacentrum.perun.core.api.PerunClient)4 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)4