use of com.yahoo.athenz.zms.ServiceIdentity 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);
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"));
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnection method getServiceIdentity.
@Override
public ServiceIdentity getServiceIdentity(String domainName, String serviceName) {
final String caller = "getServiceIdentity";
try (PreparedStatement ps = con.prepareStatement(SQL_GET_SERVICE)) {
ps.setString(1, domainName);
ps.setString(2, serviceName);
try (ResultSet rs = executeQuery(ps, caller)) {
if (rs.next()) {
ServiceIdentity serviceIdentity = new ServiceIdentity().setName(ZMSUtils.serviceResourceName(domainName, serviceName)).setDescription(saveValue(rs.getString(ZMSConsts.DB_COLUMN_DESCRIPTION))).setModified(Timestamp.fromMillis(rs.getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED).getTime())).setProviderEndpoint(saveValue(rs.getString(ZMSConsts.DB_COLUMN_PROVIDER_ENDPOINT))).setExecutable(saveValue(rs.getString(ZMSConsts.DB_COLUMN_EXECTUABLE))).setUser(saveValue(rs.getString(ZMSConsts.DB_COLUMN_SVC_USER))).setGroup(saveValue(rs.getString(ZMSConsts.DB_COLUMN_SVC_GROUP)));
return serviceIdentity;
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
return null;
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testInsertServiceException.
@Test
public void testInsertServiceException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = new ServiceIdentity().setName("my-domain.service1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.insertServiceIdentity("my-domain", service);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testGetServiceIdentityNoMatch.
@Test
public void testGetServiceIdentityNoMatch() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(false);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = jdbcConn.getServiceIdentity("my-domain", "service1");
assertNull(service);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataCacheTest method testSingleHostSingleService.
@Test
public void testSingleHostSingleService() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service = new ServiceIdentity();
service.setName("testDomain.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
DataCache cache = new DataCache();
cache.processServiceIdentity(service);
Map<String, Set<String>> hostMap = cache.getHostMap();
assertEquals(hostMap.size(), 1);
assertTrue(hostMap.containsKey("host1"));
Set<String> set = hostMap.get("host1");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
}
Aggregations