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"));
}
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"));
}
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"));
}
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;
}
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;
}
Aggregations