Search in sources :

Example 1 with ResourceTag

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

the class ResourcesManagerBlImpl method removeResourceTagFromResource.

@Override
public void removeResourceTagFromResource(PerunSession perunSession, ResourceTag resourceTag, Resource resource) throws ResourceTagNotAssignedException {
    List<ResourceTag> allResourceTags = this.getAllResourcesTagsForResource(perunSession, resource);
    if (!allResourceTags.contains(resourceTag))
        throw new ResourceTagNotAssignedException(resourceTag);
    getResourcesManagerImpl().removeResourceTagFromResource(perunSession, resourceTag, resource);
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) ResourceTagNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotAssignedException)

Example 2 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method getAllResourcesByResourceTag.

@Test
public void getAllResourcesByResourceTag() throws Exception {
    System.out.println(CLASS_NAME + "getAllResourcesByResourceTag");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    ResourceTag tag = setUpResourceTag();
    resourcesManager.assignResourceTagToResource(sess, tag, resource);
    List<Resource> resources = perun.getResourcesManager().getAllResourcesByResourceTag(sess, tag);
    assertTrue("Resource with tag is not returned by same tag", resources.contains(resource));
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method copyResourceWithEverythingFilled.

@Test
public void copyResourceWithEverythingFilled() throws Exception {
    System.out.println(CLASS_NAME + "copyResourceWithEverythingFilled");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    resource.setVoId(vo.getId());
    resource.setFacilityId(facility.getId());
    assertNotNull("resource", resource);
    // Setup of groups,services and tags
    Member member = setUpMember(vo);
    group = setUpGroup(vo, member);
    service = setUpService();
    ResourceTag resTag = setUpResourceTag();
    resourcesManager.assignService(sess, resource, service);
    resourcesManager.assignGroupToResource(sess, group, resource, false, false, false);
    resourcesManager.assignResourceTagToResource(sess, resTag, resource);
    Resource destinationResource = new Resource();
    destinationResource.setName("DestinationResource");
    destinationResource.setDescription("DestinationResource");
    destinationResource.setVoId(vo.getId());
    destinationResource.setFacilityId(facility.getId());
    // Setup of resource-member attribute
    AttributeDefinition resourceMemberAttrDef = new AttributeDefinition();
    resourceMemberAttrDef.setNamespace(AttributesManager.NS_MEMBER_RESOURCE_ATTR_DEF);
    resourceMemberAttrDef.setFriendlyName("memberResourceAttribute");
    resourceMemberAttrDef.setType(Integer.class.getName());
    resourceMemberAttrDef = perun.getAttributesManagerBl().createAttribute(sess, resourceMemberAttrDef);
    Attribute resourceMemberAttr = perun.getAttributesManagerBl().getAttribute(sess, member, resource, resourceMemberAttrDef.getName());
    resourceMemberAttr.setValue(1);
    perun.getAttributesManagerBl().setAttribute(sess, member, resource, resourceMemberAttr);
    resourcesManager.copyResource(sess, resource, destinationResource, true);
    Resource createdResource = resourcesManager.getResourceByName(sess, vo, facility, destinationResource.getName());
    assertNotNull("Resource was not created.", createdResource);
    // group, service and resource tags copy check
    assertFalse("Group assigned to original resource not copied to destination resource.", resourcesManager.getAssignedGroups(sess, createdResource).isEmpty());
    assertFalse("Service not copied to destination resource.", resourcesManager.getAssignedServices(sess, createdResource).isEmpty());
    assertFalse("Resource tag not created for destination resource.", resourcesManager.getAllResourcesTagsForResource(sess, createdResource).isEmpty());
    // resource-member attributes check
    List<Attribute> resMembAttrs = perun.getAttributesManagerBl().getAttributes(sess, member, createdResource);
    assertFalse("Created resource does not contain any resource-member attributes.", resMembAttrs.isEmpty());
    assertTrue("Created resource does not contain template resource-member attribute (or copied value of attribute is wrong).", resMembAttrs.contains(resourceMemberAttr));
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) Attribute(cz.metacentrum.perun.core.api.Attribute) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method getResourceAssignmentsContainsTags.

@Test
public void getResourceAssignmentsContainsTags() throws Exception {
    System.out.println(CLASS_NAME + "getResourceAssignmentsContainsTags");
    vo = setUpVo();
    member = setUpMember(vo);
    group = setUpGroup(vo, member);
    facility = setUpFacility();
    resource = setUpResource();
    ResourceTag resourceTag = new ResourceTag(1, "This is a tag", vo.getId());
    resourcesManager.createResourceTag(sess, resourceTag, vo);
    resourcesManager.assignGroupToResource(sess, group, resource, false, false, false);
    resourcesManager.assignResourceTagToResource(sess, resourceTag, resource);
    List<AssignedResource> resources = resourcesManager.getResourceAssignments(sess, group, null);
    assertThat(resources.get(0).getResourceTags()).containsOnly(resourceTag);
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method getAllResourcesTagsForVo.

@Test
public void getAllResourcesTagsForVo() throws Exception {
    System.out.println(CLASS_NAME + "getAllResourcesTagsForVo");
    vo = setUpVo();
    ResourceTag tag = setUpResourceTag();
    List<ResourceTag> tags = perun.getResourcesManager().getAllResourcesTagsForVo(sess, vo);
    assertTrue("Created tag is not returned from VO", tags.contains(tag));
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

ResourceTag (cz.metacentrum.perun.core.api.ResourceTag)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)5 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)5 Test (org.junit.Test)5 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)4 EnrichedResource (cz.metacentrum.perun.core.api.EnrichedResource)4 Resource (cz.metacentrum.perun.core.api.Resource)4 RichResource (cz.metacentrum.perun.core.api.RichResource)4 BanRemovedForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource)2 BanSetForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource)2 BanUpdatedForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource)2 GroupAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource)2 GroupRemovedFromResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource)2 ServiceAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource)2 ServiceRemovedFromResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource)2 AssignedMember (cz.metacentrum.perun.core.api.AssignedMember)2 Attribute (cz.metacentrum.perun.core.api.Attribute)2 Member (cz.metacentrum.perun.core.api.Member)2 ResourceTagAlreadyAssignedException (cz.metacentrum.perun.core.api.exceptions.ResourceTagAlreadyAssignedException)2 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)1