Search in sources :

Example 6 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method setUpResourceTag.

private ResourceTag setUpResourceTag() throws Exception {
    ResourceTag tag = new ResourceTag(0, "ResourceManagerTestResourceTag", vo.getId());
    tag = perun.getResourcesManager().createResourceTag(sess, tag, vo);
    assertNotNull("unable to create testing ResourceTag", tag);
    return tag;
}
Also used : ResourceTag(cz.metacentrum.perun.core.api.ResourceTag)

Example 7 with ResourceTag

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

the class ResourcesManagerEntryIntegrationTest method getAllResourcesTagsForResource.

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

Example 8 with ResourceTag

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

the class ResourcesManagerBlImpl method deleteAllResourcesTagsForVo.

@Override
public void deleteAllResourcesTagsForVo(PerunSession perunSession, Vo vo) throws ResourceTagAlreadyAssignedException {
    List<ResourceTag> resourcesTagForVo = this.getAllResourcesTagsForVo(perunSession, vo);
    for (ResourceTag rt : resourcesTagForVo) {
        List<Resource> tagResources = this.getAllResourcesByResourceTag(perunSession, rt);
        if (!tagResources.isEmpty())
            throw new ResourceTagAlreadyAssignedException("The resourceTag is alreadyUsed for some resources.", rt);
    }
    getResourcesManagerImpl().deleteAllResourcesTagsForVo(perunSession, vo);
}
Also used : ResourceTagAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagAlreadyAssignedException) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Resource(cz.metacentrum.perun.core.api.Resource) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource)

Example 9 with ResourceTag

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

the class ResourcesManagerBlImpl method copyResource.

@Override
public Resource copyResource(PerunSession sess, Resource templateResource, Resource destinationResource, boolean withGroups) throws ResourceExistsException {
    Resource newResource = new Resource();
    Vo destinationVo = this.getVo(sess, destinationResource);
    Facility destinationFacility = this.getFacility(sess, destinationResource);
    newResource.setName(destinationResource.getName());
    newResource = this.createResource(sess, newResource, destinationVo, destinationFacility);
    // resource attributes
    List<Attribute> templateResourceAttributes = perunBl.getAttributesManagerBl().getAttributes(sess, templateResource);
    // Remove all virt and core attributes before setting
    templateResourceAttributes.removeIf(resourceAttribute -> resourceAttribute.getNamespace().startsWith(AttributesManager.NS_RESOURCE_ATTR_VIRT) || resourceAttribute.getNamespace().startsWith(AttributesManager.NS_RESOURCE_ATTR_CORE));
    try {
        perunBl.getAttributesManagerBl().setAttributes(sess, newResource, templateResourceAttributes);
    } catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
        throw new ConsistencyErrorException("DB inconsistency while copying attributes from one resource to another. Cause:{}", ex);
    }
    // if withGroups is true we also copy groups and group-resource/member-resource attributes
    if (withGroups) {
        List<AssignedGroup> templateResourceGroups = perunBl.getResourcesManagerBl().getGroupAssignments(sess, templateResource, List.of());
        try {
            for (AssignedGroup assignedGroup : templateResourceGroups) {
                // assign only direct group-resource assignments
                if (assignedGroup.getSourceGroupId() == null) {
                    assignGroupToResource(sess, assignedGroup.getEnrichedGroup().getGroup(), newResource, false, assignedGroup.getStatus().equals(GroupResourceStatus.INACTIVE), assignedGroup.isAutoAssignSubgroups());
                }
                List<Attribute> templateGroupResourceAttributes = perunBl.getAttributesManagerBl().getAttributes(sess, templateResource, assignedGroup.getEnrichedGroup().getGroup());
                // Remove all virt attributes before setting
                templateGroupResourceAttributes.removeIf(groupResourceAttribute -> groupResourceAttribute.getNamespace().startsWith(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT));
                perunBl.getAttributesManagerBl().setAttributes(sess, newResource, assignedGroup.getEnrichedGroup().getGroup(), templateGroupResourceAttributes);
            }
        } catch (GroupResourceMismatchException | WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
            throw new ConsistencyErrorException("DB inconsistency while copying group-resource attributes. Cause:{}", ex);
        }
        List<Member> templateResourceMembers = perunBl.getResourcesManagerBl().getAssignedMembers(sess, templateResource);
        try {
            for (Member member : templateResourceMembers) {
                List<Attribute> templateMemberResourceAttributes = perunBl.getAttributesManagerBl().getAttributes(sess, member, templateResource);
                // Remove all virt attributes before setting
                templateMemberResourceAttributes.removeIf(memberResourceAttribute -> memberResourceAttribute.getNamespace().startsWith(AttributesManager.NS_MEMBER_RESOURCE_ATTR_VIRT));
                perunBl.getAttributesManagerBl().setAttributes(sess, member, newResource, templateMemberResourceAttributes);
            }
        } catch (MemberResourceMismatchException | WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
            throw new ConsistencyErrorException("DB inconsistency while copying group-resource attributes. Cause:{}", ex);
        }
    }
    // services
    List<Service> services = getAssignedServices(sess, templateResource);
    for (Service service : services) {
        try {
            getResourcesManagerImpl().assignService(sess, newResource, service);
        } catch (ServiceAlreadyAssignedException ex) {
            throw new ConsistencyErrorException("Service was already assigned to this resource. {}", ex);
        }
    }
    // tags
    List<ResourceTag> templateResourceTags = getAllResourcesTagsForResource(sess, templateResource);
    for (ResourceTag resourceTag : templateResourceTags) {
        getResourcesManagerImpl().assignResourceTagToResource(sess, resourceTag, newResource);
    }
    return newResource;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Resource(cz.metacentrum.perun.core.api.Resource) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) Service(cz.metacentrum.perun.core.api.Service) ServiceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyAssignedException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) RichMember(cz.metacentrum.perun.core.api.RichMember) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup)

Example 10 with ResourceTag

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

the class ResourcesManagerBlImpl method assignResourceTagToResource.

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

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