Search in sources :

Example 1 with DomainModifiedList

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

the class FileConnection method listModifiedDomains.

@Override
public DomainModifiedList listModifiedDomains(long modifiedSince) {
    DomainModifiedList domainModifiedList = new DomainModifiedList();
    List<DomainModified> nameMods = new ArrayList<DomainModified>();
    List<String> domainList = listDomains(null, modifiedSince);
    // Now set the dest for the returned domain names
    String dirName = rootDir.getAbsolutePath() + File.separator;
    for (String dname : domainList) {
        long ts = 0;
        try {
            File dfile = new File(dirName + dname);
            ts = dfile.lastModified();
            if (ts <= modifiedSince) {
                continue;
            }
        } catch (Exception exc) {
            LOG.error("FileStructStore: FAILED to get timestamp for file " + dname + ", error: " + exc.getMessage());
        }
        DomainModified dm = new DomainModified().setName(dname).setModified(ts);
        nameMods.add(dm);
    }
    domainModifiedList.setNameModList(nameMods);
    return domainModifiedList;
}
Also used : DomainModifiedList(com.yahoo.athenz.zms.DomainModifiedList) ArrayList(java.util.ArrayList) DomainModified(com.yahoo.athenz.zms.DomainModified) File(java.io.File) ResourceException(com.yahoo.athenz.zms.ResourceException) IOException(java.io.IOException)

Example 2 with DomainModifiedList

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

the class JDBCConnectionTest method testListModifiedDomainsNoEntries.

@Test
public void testListModifiedDomainsNoEntries() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // no entries
    Mockito.when(mockResultSet.next()).thenReturn(false);
    DomainModifiedList list = jdbcConn.listModifiedDomains(1454358900);
    assertEquals(0, list.getNameModList().size());
    jdbcConn.close();
}
Also used : DomainModifiedList(com.yahoo.athenz.zms.DomainModifiedList) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 3 with DomainModifiedList

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

the class JDBCConnection method listModifiedDomains.

@Override
public DomainModifiedList listModifiedDomains(long modifiedSince) {
    final String caller = "listModifiedDomains";
    DomainModifiedList domainModifiedList = new DomainModifiedList();
    List<DomainModified> nameMods = new ArrayList<DomainModified>();
    try (PreparedStatement ps = prepareDomainScanStatement(null, modifiedSince)) {
        try (ResultSet rs = executeQuery(ps, caller)) {
            while (rs.next()) {
                DomainModified dm = new DomainModified().setName(rs.getString(ZMSConsts.DB_COLUMN_NAME)).setModified(rs.getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED).getTime());
                nameMods.add(dm);
            }
        }
    } catch (SQLException ex) {
        throw sqlError(ex, caller);
    }
    domainModifiedList.setNameModList(nameMods);
    return domainModifiedList;
}
Also used : DomainModifiedList(com.yahoo.athenz.zms.DomainModifiedList) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DomainModified(com.yahoo.athenz.zms.DomainModified)

Example 4 with DomainModifiedList

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

the class JDBCConnectionTest method testListModifiedDomains.

@Test
public void testListModifiedDomains() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // 3 domains
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("domain1").thenReturn("domain2").thenReturn(// 3 domains
    "domain3");
    Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
    DomainModifiedList list = jdbcConn.listModifiedDomains(1454358900);
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(Matchers.eq(1), Matchers.eq(new java.sql.Timestamp(1454358900)), Matchers.isA(Calendar.class));
    assertEquals(3, list.getNameModList().size());
    boolean domain1Found = false;
    boolean domain2Found = false;
    boolean domain3Found = false;
    for (DomainModified dom : list.getNameModList()) {
        switch(dom.getName()) {
            case "domain1":
                domain1Found = true;
                break;
            case "domain2":
                domain2Found = true;
                break;
            case "domain3":
                domain3Found = true;
                break;
        }
    }
    assertTrue(domain1Found);
    assertTrue(domain2Found);
    assertTrue(domain3Found);
    jdbcConn.close();
}
Also used : DomainModifiedList(com.yahoo.athenz.zms.DomainModifiedList) Calendar(java.util.Calendar) DomainModified(com.yahoo.athenz.zms.DomainModified) Timestamp(com.yahoo.rdl.Timestamp) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)4 DomainModified (com.yahoo.athenz.zms.DomainModified)3 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 ResourceException (com.yahoo.athenz.zms.ResourceException)1 Timestamp (com.yahoo.rdl.Timestamp)1 File (java.io.File)1 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Calendar (java.util.Calendar)1