Search in sources :

Example 41 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestActionDao method testUpdateAction.

@Test
public void testUpdateAction() throws Exception {
    Map<String, String> args = new HashMap<>();
    ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
    actionDao.insert(actionInfo);
    actionInfo.setSuccessful(true);
    actionDao.update(actionInfo);
    ActionInfo dbActionInfo = actionDao.getById(actionInfo.getActionId());
    Assert.assertTrue(actionInfo.equals(dbActionInfo));
}
Also used : HashMap(java.util.HashMap) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Example 42 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestActionDao method testGetNewDeleteAction.

@Test
public void testGetNewDeleteAction() throws Exception {
    Map<String, String> args = new HashMap<>();
    ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
    List<ActionInfo> actionInfoList = actionDao.getLatestActions(0);
    // Get from empty table
    Assert.assertTrue(actionInfoList.size() == 0);
    actionDao.insert(actionInfo);
    actionInfo.setActionId(2);
    actionDao.insert(actionInfo);
    actionInfoList = actionDao.getLatestActions(0);
    Assert.assertTrue(actionInfoList.size() == 2);
    actionInfoList = actionDao.getByIds(Arrays.asList(1L, 2L));
    Assert.assertTrue(actionInfoList.size() == 2);
    actionDao.delete(actionInfo.getActionId());
    actionInfoList = actionDao.getAll();
    Assert.assertTrue(actionInfoList.size() == 1);
}
Also used : HashMap(java.util.HashMap) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Example 43 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestActionDao method testGetLatestActionListByFinishAndSuccess.

@Test
public void testGetLatestActionListByFinishAndSuccess() {
    Map<String, String> args = new HashMap<>();
    ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
    List<ActionInfo> actionInfoList = actionDao.getLatestActions("cache", 0, false, true);
    // Get from empty table
    Assert.assertTrue(actionInfoList.size() == 0);
    actionDao.insert(actionInfo);
    actionInfo.setActionId(2);
    actionDao.insert(actionInfo);
    actionInfoList = actionDao.getLatestActions("cache", 0, false, true);
    Assert.assertTrue(actionInfoList.size() == 2);
    actionInfoList = actionDao.getByIds(Arrays.asList(1L, 2L));
    Assert.assertTrue(actionInfoList.size() == 2);
    actionInfoList = actionDao.getLatestActions("cache", 1, false, true);
    Assert.assertTrue(actionInfoList.size() == 1);
}
Also used : HashMap(java.util.HashMap) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Example 44 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestActionDao method testMaxId.

@Test
public void testMaxId() throws Exception {
    Map<String, String> args = new HashMap<>();
    ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100);
    Assert.assertTrue(actionDao.getMaxId() == 0);
    actionDao.insert(actionInfo);
    Assert.assertTrue(actionDao.getMaxId() == 2);
}
Also used : HashMap(java.util.HashMap) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Example 45 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestSmartAdmin method test.

@Test
public void test() throws Exception {
    waitTillSSMExitSafeMode();
    SmartAdmin admin = null;
    try {
        admin = new SmartAdmin(smartContext.getConf());
        // test listRulesInfo and submitRule
        List<RuleInfo> ruleInfos = admin.listRulesInfo();
        int ruleCounts0 = ruleInfos.size();
        long ruleId = admin.submitRule("file: every 5s | path matches \"/foo*\"| cache", RuleState.DRYRUN);
        ruleInfos = admin.listRulesInfo();
        int ruleCounts1 = ruleInfos.size();
        assertEquals(1, ruleCounts1 - ruleCounts0);
        // test checkRule
        // if success ,no Exception throw
        admin.checkRule("file: every 5s | path matches \"/foo*\"| cache");
        boolean caughtException = false;
        try {
            admin.checkRule("file.path");
        } catch (IOException e) {
            caughtException = true;
        }
        assertTrue(caughtException);
        // test getRuleInfo
        RuleInfo ruleInfo = admin.getRuleInfo(ruleId);
        assertNotEquals(null, ruleInfo);
        // test disableRule
        admin.disableRule(ruleId, true);
        assertEquals(RuleState.DISABLED, admin.getRuleInfo(ruleId).getState());
        // test activateRule
        admin.activateRule(ruleId);
        assertEquals(RuleState.ACTIVE, admin.getRuleInfo(ruleId).getState());
        // test deleteRule
        admin.deleteRule(ruleId, true);
        assertEquals(RuleState.DELETED, admin.getRuleInfo(ruleId).getState());
        // test cmdletInfo
        long id = admin.submitCmdlet("cache -file /foo*");
        CmdletInfo cmdletInfo = admin.getCmdletInfo(id);
        assertTrue("cache -file /foo*".equals(cmdletInfo.getParameters()));
        // test actioninfo
        List<Long> aidlist = cmdletInfo.getAids();
        assertNotEquals(0, aidlist.size());
        ActionInfo actionInfo = admin.getActionInfo(aidlist.get(0));
        assertEquals(id, actionInfo.getCmdletId());
        // test listActionInfoOfLastActions
        admin.listActionInfoOfLastActions(2);
        List<ActionDescriptor> actions = admin.listActionsSupported();
        assertTrue(actions.size() > 0);
        // test client close
        admin.close();
        try {
            admin.getRuleInfo(ruleId);
            Assert.fail("Should fail because admin has closed.");
        } catch (IOException e) {
        }
        admin = null;
    } finally {
        if (admin != null) {
            admin.close();
        }
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionDescriptor(org.smartdata.model.ActionDescriptor) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Aggregations

ActionInfo (org.smartdata.model.ActionInfo)48 Test (org.junit.Test)23 HashMap (java.util.HashMap)16 CmdletInfo (org.smartdata.model.CmdletInfo)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 SmartAdmin (org.smartdata.admin.SmartAdmin)5 MetaStore (org.smartdata.metastore.MetaStore)5 Path (org.apache.hadoop.fs.Path)4 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)4 MetaStoreException (org.smartdata.metastore.MetaStoreException)4 FileInfo (org.smartdata.model.FileInfo)4 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 ActionScheduler (org.smartdata.model.action.ActionScheduler)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 QueueFullException (org.smartdata.exception.QueueFullException)2 DetailedFileAction (org.smartdata.model.DetailedFileAction)2