Search in sources :

Example 1 with ActionDescriptor

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

the class ServerProtocolsServerSideTranslator method listActionsSupported.

@Override
public ListActionsSupportedResponseProto listActionsSupported(RpcController controller, ListActionsSupportedRequestProto req) throws ServiceException {
    try {
        List<ActionDescriptor> adList = server.listActionsSupported();
        List<ActionDescriptorProto> prolist = new ArrayList<>();
        for (ActionDescriptor a : adList) {
            prolist.add(ProtoBufferHelper.convert(a));
        }
        return ListActionsSupportedResponseProto.newBuilder().addAllActDesList(prolist).build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) ActionDescriptor(org.smartdata.model.ActionDescriptor) ActionDescriptorProto(org.smartdata.protocol.AdminServerProto.ActionDescriptorProto) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with ActionDescriptor

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

the class AdminProtocolClientSideTranslator method listActionsSupported.

@Override
public List<ActionDescriptor> listActionsSupported() throws IOException {
    ListActionsSupportedRequestProto req = ListActionsSupportedRequestProto.newBuilder().build();
    try {
        List<ActionDescriptorProto> prolist = rpcProxy.listActionsSupported(null, req).getActDesListList();
        List<ActionDescriptor> list = new ArrayList<>();
        for (ActionDescriptorProto a : prolist) {
            list.add(ProtoBufferHelper.convert(a));
        }
        return list;
    } catch (ServiceException e) {
        throw ProtoBufferHelper.getRemoteException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) ActionDescriptor(org.smartdata.model.ActionDescriptor) ListActionsSupportedRequestProto(org.smartdata.protocol.AdminServerProto.ListActionsSupportedRequestProto) ActionDescriptorProto(org.smartdata.protocol.AdminServerProto.ActionDescriptorProto) ArrayList(java.util.ArrayList)

Example 3 with ActionDescriptor

use of org.smartdata.model.ActionDescriptor 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

ActionDescriptor (org.smartdata.model.ActionDescriptor)3 ServiceException (com.google.protobuf.ServiceException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ActionDescriptorProto (org.smartdata.protocol.AdminServerProto.ActionDescriptorProto)2 Test (org.junit.Test)1 SmartAdmin (org.smartdata.admin.SmartAdmin)1 ActionInfo (org.smartdata.model.ActionInfo)1 CmdletInfo (org.smartdata.model.CmdletInfo)1 RuleInfo (org.smartdata.model.RuleInfo)1 ListActionsSupportedRequestProto (org.smartdata.protocol.AdminServerProto.ListActionsSupportedRequestProto)1