Search in sources :

Example 16 with ServiceIdentity

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"));
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) HostServices(com.yahoo.athenz.zts.HostServices) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 17 with ServiceIdentity

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;
}
Also used : SQLException(java.sql.SQLException) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 18 with ServiceIdentity

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();
}
Also used : SQLException(java.sql.SQLException) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 19 with ServiceIdentity

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();
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 20 with ServiceIdentity

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

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