Search in sources :

Example 1 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStore method getHostServices.

// API
public HostServices getHostServices(String host) {
    HostServices result = new HostServices().setHost(host);
    try {
        hostRLock.lock();
        /* we need to make a copy of our list as oppose to just returning
             * a reference since once we release the host read lock that list
             * can be modified by the updater thread */
        List<String> services = hostCache.get(host);
        if (services != null) {
            result.setNames(new ArrayList<>(services));
        }
    } finally {
        hostRLock.unlock();
    }
    return result;
}
Also used : HostServices(com.yahoo.athenz.zts.HostServices)

Example 2 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheAddedHosts.

@Test
public void testAddDomainToCacheAddedHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    dataCache.processServiceIdentity(service);
    services.add(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* added hosts */
    dataCache = new DataCache();
    service = new ServiceIdentity();
    service.setName("coretech.storage");
    hosts = new ArrayList<>();
    hosts.add("host1");
    hosts.add("host2");
    service.setHosts(hosts);
    services = new ArrayList<>();
    dataCache.processServiceIdentity(service);
    services.add(service);
    domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
    hostServices = store.getHostServices("host2");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 3 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testProcessDomainServiceIdentitiesNullPolicies.

@Test
public void testProcessDomainServiceIdentitiesNullPolicies() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DataCache dataCache = new DataCache();
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    dataCache.setDomainData(domainData);
    store.processDomainServiceIdentities(domainData, dataCache);
    HostServices hostServices = store.getHostServices("host1");
    List<String> hosts = hostServices.getNames();
    assertNull(hosts);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 4 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testProcessDomainServiceIdentities.

@Test
public void testProcessDomainServiceIdentities() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domainData.setServices(services);
    DataCache dataCache = new DataCache();
    dataCache.setDomainData(domainData);
    store.processDomainServiceIdentities(domainData, dataCache);
    store.addDomainToCache(domainData.getName(), dataCache);
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 5 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testGetHostServicesHostUpdated.

@Test
public void testGetHostServicesHostUpdated() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host2", services);
    Map<String, Set<String>> hostMap = new HashMap<>();
    Set<String> newServices = new HashSet<>();
    newServices.add("coretech.backup");
    hostMap.put("host3", newServices);
    newServices = new HashSet<>();
    newServices.add("sports.backup");
    hostMap.put("host1", newServices);
    store.addHostEntries(hostMap);
    Map<String, Set<String>> remMap = new HashMap<>();
    Set<String> remServices = new HashSet<>();
    remServices.add("sports.storage");
    remMap.put("host1", remServices);
    store.removeHostEntries(remMap);
    HostServices hostServices = store.getHostServices("host1");
    List<String> hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.backup"));
    hostServices = store.getHostServices("host2");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.storage"));
    hostServices = store.getHostServices("host3");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.backup"));
}
Also used : HostServices(com.yahoo.athenz.zts.HostServices) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Aggregations

HostServices (com.yahoo.athenz.zts.HostServices)10 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)9 Test (org.testng.annotations.Test)9 DataCache (com.yahoo.athenz.zts.cache.DataCache)6