Search in sources :

Example 26 with ServiceIdentity

use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.

the class DataCacheTest method testSingleHostMultipleServices.

@Test
public void testSingleHostMultipleServices() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    ServiceIdentity service1 = new ServiceIdentity();
    service1.setName("testDomain.storage1");
    List<String> hosts1 = new ArrayList<>();
    hosts1.add("host1");
    service1.setHosts(hosts1);
    ServiceIdentity service2 = new ServiceIdentity();
    service2.setName("testDomain.storage2");
    List<String> hosts2 = new ArrayList<>();
    hosts2.add("host1");
    service2.setHosts(hosts2);
    DataCache cache = new DataCache();
    cache.processServiceIdentity(service1);
    cache.processServiceIdentity(service2);
    Map<String, Set<String>> hostMap = cache.getHostMap();
    assertEquals(hostMap.size(), 1);
    assertTrue(hostMap.containsKey("host1"));
    Set<String> set = hostMap.get("host1");
    assertEquals(set.size(), 2);
    assertTrue(set.contains("testDomain.storage1"));
    assertTrue(set.contains("testDomain.storage2"));
}
Also used : Set(java.util.Set) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 27 with ServiceIdentity

use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.

the class DataCacheTest method testMultipleHostsMultipleServices.

@Test
public void testMultipleHostsMultipleServices() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    ServiceIdentity service1 = new ServiceIdentity();
    service1.setName("testDomain.storage1");
    List<String> hosts1 = new ArrayList<>();
    hosts1.add("host1");
    hosts1.add("host2");
    service1.setHosts(hosts1);
    ServiceIdentity service2 = new ServiceIdentity();
    service2.setName("testDomain.storage2");
    List<String> hosts2 = new ArrayList<>();
    hosts2.add("host1");
    hosts2.add("host3");
    service2.setHosts(hosts2);
    DataCache cache = new DataCache();
    cache.processServiceIdentity(service1);
    cache.processServiceIdentity(service2);
    Map<String, Set<String>> hostMap = cache.getHostMap();
    assertEquals(hostMap.size(), 3);
    assertTrue(hostMap.containsKey("host1"));
    assertTrue(hostMap.containsKey("host2"));
    assertTrue(hostMap.containsKey("host3"));
    Set<String> set = hostMap.get("host1");
    assertEquals(set.size(), 2);
    assertTrue(set.contains("testDomain.storage1"));
    assertTrue(set.contains("testDomain.storage2"));
    set = hostMap.get("host2");
    assertEquals(set.size(), 1);
    assertTrue(set.contains("testDomain.storage1"));
    set = hostMap.get("host3");
    assertEquals(set.size(), 1);
    assertTrue(set.contains("testDomain.storage2"));
}
Also used : Set(java.util.Set) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 28 with ServiceIdentity

use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheRemovedPublicKeysVersions.

@Test
public void testAddDomainToCacheRemovedPublicKeysVersions() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    setServicePublicKey(service, "0", ZTS_Y64_CERT0);
    List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
    com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
    publicKey.setKey(ZTS_Y64_CERT1);
    publicKey.setId("1");
    publicKeys.add(publicKey);
    publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
    publicKey.setKey(ZTS_Y64_CERT2);
    publicKey.setId("2");
    publicKeys.add(publicKey);
    service.setPublicKeys(publicKeys);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* update multiple version public keys */
    dataCache = new DataCache();
    service = new ServiceIdentity();
    service.setName("coretech.storage");
    publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
    publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
    publicKey.setKey(ZTS_Y64_CERT0);
    publicKey.setId("0");
    publicKeys.add(publicKey);
    publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
    publicKey.setKey(ZTS_Y64_CERT2);
    publicKey.setId("2");
    publicKeys.add(publicKey);
    service.setPublicKeys(publicKeys);
    services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    assertEquals(store.getPublicKey("coretech", "storage", "0"), ZTS_PEM_CERT0);
    assertNull(store.getPublicKey("coretech", "storage", "1"));
    assertEquals(store.getPublicKey("coretech", "storage", "2"), ZTS_PEM_CERT2);
    assertNull(store.getPublicKey("coretech", "storage", "3"));
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) Test(org.testng.annotations.Test)

Example 29 with ServiceIdentity

use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.

the class FileConnection method getAthenzDomain.

@Override
public AthenzDomain getAthenzDomain(String domainName) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "getAthenzDomain");
    }
    AthenzDomain athenzDomain = new AthenzDomain(domainName);
    athenzDomain.setDomain(getDomain(domainStruct));
    if (domainStruct.getRoles() != null) {
        athenzDomain.setRoles(new ArrayList<Role>(domainStruct.getRoles().values()));
    }
    if (domainStruct.getPolicies() != null) {
        athenzDomain.setPolicies(new ArrayList<Policy>(domainStruct.getPolicies().values()));
    }
    if (domainStruct.getServices() != null) {
        athenzDomain.setServices(new ArrayList<ServiceIdentity>(domainStruct.getServices().values()));
    }
    return athenzDomain;
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) Policy(com.yahoo.athenz.zms.Policy) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity)

Example 30 with ServiceIdentity

use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.

the class FileConnection method updatePublicKeyEntry.

@Override
public boolean updatePublicKeyEntry(String domainName, String serviceName, PublicKeyEntry publicKey) {
    DomainStruct domainStruct = getDomainStruct(domainName);
    if (domainStruct == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "updatePublicKeyEntry");
    }
    ServiceIdentity service = getServiceObject(domainStruct, serviceName);
    if (service == null) {
        throw ZMSUtils.error(ResourceException.NOT_FOUND, "service not found", "updatePublicKeyEntry");
    }
    updatePublicKeyEntry(service, publicKey);
    putDomainStruct(domainName, domainStruct);
    return true;
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity)

Aggregations

ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)53 Test (org.testng.annotations.Test)32 ArrayList (java.util.ArrayList)29 DomainData (com.yahoo.athenz.zms.DomainData)21 DataCache (com.yahoo.athenz.zts.cache.DataCache)17 Role (com.yahoo.athenz.zms.Role)11 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)11 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)11 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)11 RoleMember (com.yahoo.athenz.zms.RoleMember)8 SignedDomain (com.yahoo.athenz.zms.SignedDomain)8 Domain (com.yahoo.athenz.zms.Domain)6 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)5 HostServices (com.yahoo.athenz.zts.HostServices)5 Set (java.util.Set)5 Policy (com.yahoo.athenz.zms.Policy)4 ResourceException (com.yahoo.athenz.zms.ResourceException)4 SQLException (java.sql.SQLException)4 Assertion (com.yahoo.athenz.zms.Assertion)3 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)3