Search in sources :

Example 1 with EnrichedHost

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

the class FacilitiesManagerEntry method getEnrichedHosts.

@Override
public List<EnrichedHost> getEnrichedHosts(PerunSession sess, Facility facility, List<String> attrNames) throws AttributeNotExistsException, FacilityNotExistsException, PrivilegeException {
    List<Host> hosts = getHosts(sess, facility);
    List<EnrichedHost> enrichedHosts = new ArrayList<>();
    if (hosts.isEmpty())
        return enrichedHosts;
    Host host1 = hosts.get(0);
    List<String> allowedAttributes = new ArrayList<>();
    // Filtering attributes
    for (String attrName : attrNames) {
        if (AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attrName), host1)) {
            allowedAttributes.add(attrName);
        }
    }
    for (Host host : hosts) {
        List<Attribute> hostAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, host, allowedAttributes);
        enrichedHosts.add(new EnrichedHost(host, hostAttributes));
    }
    return enrichedHosts;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) EnrichedHost(cz.metacentrum.perun.core.api.EnrichedHost) EnrichedHost(cz.metacentrum.perun.core.api.EnrichedHost) Host(cz.metacentrum.perun.core.api.Host)

Example 2 with EnrichedHost

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

the class FacilitiesManagerEntryIntegrationTest method getEnrichedHosts.

@Test
public void getEnrichedHosts() throws Exception {
    System.out.println(CLASS_NAME + "getEnrichedHosts");
    createdHost = facilitiesManagerEntry.addHosts(sess, hosts, facility).get(0);
    // set this host for deletion - host is created after adding to facility !!
    hostsForDeletion.add(hosts.get(0));
    Attribute attr = new Attribute();
    attr.setNamespace("urn:perun:host:attribute-def:opt");
    attr.setFriendlyName("host-test-for-list-of-names-attribute");
    attr.setType(String.class.getName());
    attr.setValue("HostAttributeForList");
    perun.getAttributesManagerBl().createAttribute(sess, attr);
    perun.getAttributesManagerBl().setAttribute(sess, createdHost, attr);
    List<String> attrNames = new ArrayList<>();
    attrNames.add(attr.getName());
    List<Attribute> hostAttributes = new ArrayList<>();
    hostAttributes.add(attr);
    EnrichedHost actualEnrichedHost = new EnrichedHost(createdHost, hostAttributes);
    List<EnrichedHost> expectedEnrichedHosts = facilitiesManagerEntry.getEnrichedHosts(sess, facility, attrNames);
    EnrichedHost expectedEnrichedHost = expectedEnrichedHosts.get(0);
    assertEquals("Created and returned enrichedHost should be the same", expectedEnrichedHost, actualEnrichedHost);
    assertEquals("Number of attributes should be same", expectedEnrichedHost.getHostAttributes().size(), actualEnrichedHost.getHostAttributes().size());
    assertTrue("Returned enrichedHost should have all the desired attributes", expectedEnrichedHost.getHostAttributes().containsAll(hostAttributes));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) EnrichedHost(cz.metacentrum.perun.core.api.EnrichedHost) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)2 EnrichedHost (cz.metacentrum.perun.core.api.EnrichedHost)2 ArrayList (java.util.ArrayList)2 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 Host (cz.metacentrum.perun.core.api.Host)1 Test (org.junit.Test)1