@Test public void runAction() throws Exception { StandaloneResource resource = StandaloneResourceProvider.instance ().acmeResourceForString("src/test/resources/acme/znn.acme"); IAcmeSystem sys = resource.getModel ().getSystems ().iterator ().next (); ZNNModelUpdateOperatorsImpl model = new ZNNModelUpdateOperatorsImpl(sys, "src/test/resources/acme/znn.acme"); LinkedBlockingQueue<ZNNModelUpdateOperatorsImpl> queue = new LinkedBlockingQueue<> (); queue.offer(model); ZNNStateAnalyzer analyzer = new ZNNStateAnalyzer(); Whitebox.setInternalState(analyzer, "m_modelCheckQ", queue); ZNNModelUpdateOperatorsImpl znn = new ZNNModelUpdateOperatorsImpl (sys, "src/test/resources/acme/znn.acme"); IAcmeComponent proxy = sys.getComponent ("lbproxy"); AcmeModelOperation<IAcmeComponent> cns = znn.getCommandFactory ().connectNewServerCmd (proxy, "server", "10.5.6.6", "1080"); IModelChangeBusPort announcePort = mockAnnouncePort(); assertTrue (cns.canExecute ()); generatedEvents = cns.execute (znn, announcePort); ModelReference mr = new ModelReference("ZNewsSys", "Acme"); IRainbowReportingPort port = spy(IRainbowReportingPort.class); analyzer.initialize (port); for (IRainbowMessage msg : generatedEvents) { analyzer.onEvent(mr, msg); } analyzer.runAction(); verify(port).error(eq(RainbowComponentT.ANALYSIS), eq("Failed to evaluate an expression"), any(Throwable.class)); }
@Override protected void runAction () { final ZNNModelUpdateOperatorsImpl model = m_modelCheckQ.poll (); if (model != null) { Stack<AcmeError> errors = new Stack<> (); IAcmeSystem system = model.getModelInstance (); if (m_clientsSelection != null && m_maliciousSelection != null) { NodeScopeLookup lookup = new NodeScopeLookup (); try { AcmeSet clients = RuleTypeChecker.evaluateAsSet (system, null, m_clientsSelection, errors, lookup); boolean aboveMal = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveMal, errors, lookup); boolean aboveRT = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveRT, errors, lookup); float avgRT = 0.0f; float perMal = 0.0f; if (clients != null) { float cum = 0.0f; int numMal = 0; for (Object o : clients.getValues ()) { IAcmeProperty prop; float mal = 0; if (o instanceof IAcmeElementInstance) { IAcmeElementInstance client = (IAcmeElementInstance) o; if ((prop = client.getProperty ("experRespTime")) != null) { cum += ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); } if ((prop = client.getProperty ("maliciousness")) != null) { mal = ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); log (MessageFormat.format ("{0}.maliciousness={1}", client, mal)); if (mal > 0.5) { numMal++; } } } } avgRT = cum / clients.getValues ().size (); perMal = ((float) numMal) / clients.getValues ().size () * 100f; SetSystemPropertiesCmd cmd = model.getCommandFactory ().setSystemProperties (system, avgRT, perMal, aboveRT, aboveMal); m_modelUSPort.updateModel (cmd); } } catch (AcmeException e) { m_reportingPort.error (RainbowComponentT.ANALYSIS, "Failed to evaluate an expression", e); } } } }
ZNNStateAnalyzer extends AbstractRainbowRunnable implements IRainbowAnalysis, IModelChangeBusSubscriberPort.IRainbowModelChangeCallback { @Override protected void runAction () { final ZNNModelUpdateOperatorsImpl model = m_modelCheckQ.poll (); if (model != null) { Stack<AcmeError> errors = new Stack<> (); IAcmeSystem system = model.getModelInstance (); if (m_clientsSelection != null && m_maliciousSelection != null) { NodeScopeLookup lookup = new NodeScopeLookup (); try { AcmeSet clients = RuleTypeChecker.evaluateAsSet (system, null, m_clientsSelection, errors, lookup); boolean aboveMal = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveMal, errors, lookup); boolean aboveRT = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveRT, errors, lookup); float avgRT = 0.0f; float perMal = 0.0f; if (clients != null) { float cum = 0.0f; int numMal = 0; for (Object o : clients.getValues ()) { IAcmeProperty prop; float mal = 0; if (o instanceof IAcmeElementInstance) { IAcmeElementInstance client = (IAcmeElementInstance) o; if ((prop = client.getProperty ("experRespTime")) != null) { cum += ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); } if ((prop = client.getProperty ("maliciousness")) != null) { mal = ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); log (MessageFormat.format ("{0}.maliciousness={1}", client, mal)); if (mal > 0.5) { numMal++; } } } } avgRT = cum / clients.getValues ().size (); perMal = ((float) numMal) / clients.getValues ().size () * 100f; SetSystemPropertiesCmd cmd = model.getCommandFactory ().setSystemProperties (system, avgRT, perMal, aboveRT, aboveMal); m_modelUSPort.updateModel (cmd); } } catch (AcmeException e) { m_reportingPort.error (RainbowComponentT.ANALYSIS, "Failed to evaluate an expression", e); } } } } }
ZNNStateAnalyzer extends AbstractRainbowRunnable implements IRainbowAnalysis, IModelChangeBusSubscriberPort.IRainbowModelChangeCallback { @Override protected void runAction () { final ZNNModelUpdateOperatorsImpl model = m_modelCheckQ.poll (); if (model != null) { Stack<AcmeError> errors = new Stack<> (); IAcmeSystem system = model.getModelInstance (); if (m_clientsSelection != null && m_maliciousSelection != null) { NodeScopeLookup lookup = new NodeScopeLookup (); try { AcmeSet clients = RuleTypeChecker.evaluateAsSet (system, null, m_clientsSelection, errors, lookup); boolean aboveMal = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveMal, errors, lookup); boolean aboveRT = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveRT, errors, lookup); float avgRT = 0.0f; float perMal = 0.0f; if (clients != null) { float cum = 0.0f; int numMal = 0; for (Object o : clients.getValues ()) { IAcmeProperty prop; float mal = 0; if (o instanceof IAcmeElementInstance) { IAcmeElementInstance client = (IAcmeElementInstance) o; if ((prop = client.getProperty ("experRespTime")) != null) { cum += ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); } if ((prop = client.getProperty ("maliciousness")) != null) { mal = ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); log (MessageFormat.format ("{0}.maliciousness={1}", client, mal)); if (mal > 0.5) { numMal++; } } } } avgRT = cum / clients.getValues ().size (); perMal = ((float) numMal) / clients.getValues ().size () * 100f; SetSystemPropertiesCmd cmd = model.getCommandFactory ().setSystemProperties (system, avgRT, perMal, aboveRT, aboveMal); m_modelUSPort.updateModel (cmd); } } catch (AcmeException e) { m_reportingPort.error (RainbowComponentT.ANALYSIS, "Failed to evaluate an expression", e); } } } } ZNNStateAnalyzer(); }
ZNNStateAnalyzer extends AbstractRainbowRunnable implements IRainbowAnalysis, IModelChangeBusSubscriberPort.IRainbowModelChangeCallback { @Override protected void runAction () { final ZNNModelUpdateOperatorsImpl model = m_modelCheckQ.poll (); if (model != null) { Stack<AcmeError> errors = new Stack<> (); IAcmeSystem system = model.getModelInstance (); if (m_clientsSelection != null && m_maliciousSelection != null) { NodeScopeLookup lookup = new NodeScopeLookup (); try { AcmeSet clients = RuleTypeChecker.evaluateAsSet (system, null, m_clientsSelection, errors, lookup); boolean aboveMal = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveMal, errors, lookup); boolean aboveRT = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveRT, errors, lookup); float avgRT = 0.0f; float perMal = 0.0f; if (clients != null) { float cum = 0.0f; int numMal = 0; for (Object o : clients.getValues ()) { IAcmeProperty prop; float mal = 0; if (o instanceof IAcmeElementInstance) { IAcmeElementInstance client = (IAcmeElementInstance) o; if ((prop = client.getProperty ("experRespTime")) != null) { cum += ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); } if ((prop = client.getProperty ("maliciousness")) != null) { mal = ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); log (MessageFormat.format ("{0}.maliciousness={1}", client, mal)); if (mal > 0.5) { numMal++; } } } } avgRT = cum / clients.getValues ().size (); perMal = ((float) numMal) / clients.getValues ().size () * 100f; SetSystemPropertiesCmd cmd = model.getCommandFactory ().setSystemProperties (system, avgRT, perMal, aboveRT, aboveMal); m_modelUSPort.updateModel (cmd); } } catch (AcmeException e) { m_reportingPort.error (RainbowComponentT.ANALYSIS, "Failed to evaluate an expression", e); } } } } ZNNStateAnalyzer(); @Override void initialize(IRainbowReportingPort port); @Override RainbowComponentT getComponentType(); @Override void setProperty(String key, String value); @Override String getProperty(String key); @Override void dispose(); @Override void onEvent(ModelReference reference, IRainbowMessage message); }
ZNNStateAnalyzer extends AbstractRainbowRunnable implements IRainbowAnalysis, IModelChangeBusSubscriberPort.IRainbowModelChangeCallback { @Override protected void runAction () { final ZNNModelUpdateOperatorsImpl model = m_modelCheckQ.poll (); if (model != null) { Stack<AcmeError> errors = new Stack<> (); IAcmeSystem system = model.getModelInstance (); if (m_clientsSelection != null && m_maliciousSelection != null) { NodeScopeLookup lookup = new NodeScopeLookup (); try { AcmeSet clients = RuleTypeChecker.evaluateAsSet (system, null, m_clientsSelection, errors, lookup); boolean aboveMal = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveMal, errors, lookup); boolean aboveRT = RuleTypeChecker.evaluateAsBoolean (system, null, m_aboveRT, errors, lookup); float avgRT = 0.0f; float perMal = 0.0f; if (clients != null) { float cum = 0.0f; int numMal = 0; for (Object o : clients.getValues ()) { IAcmeProperty prop; float mal = 0; if (o instanceof IAcmeElementInstance) { IAcmeElementInstance client = (IAcmeElementInstance) o; if ((prop = client.getProperty ("experRespTime")) != null) { cum += ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); } if ((prop = client.getProperty ("maliciousness")) != null) { mal = ((IAcmeFloatingPointValue) prop.getValue ()).getFloatValue (); log (MessageFormat.format ("{0}.maliciousness={1}", client, mal)); if (mal > 0.5) { numMal++; } } } } avgRT = cum / clients.getValues ().size (); perMal = ((float) numMal) / clients.getValues ().size () * 100f; SetSystemPropertiesCmd cmd = model.getCommandFactory ().setSystemProperties (system, avgRT, perMal, aboveRT, aboveMal); m_modelUSPort.updateModel (cmd); } } catch (AcmeException e) { m_reportingPort.error (RainbowComponentT.ANALYSIS, "Failed to evaluate an expression", e); } } } } ZNNStateAnalyzer(); @Override void initialize(IRainbowReportingPort port); @Override RainbowComponentT getComponentType(); @Override void setProperty(String key, String value); @Override String getProperty(String key); @Override void dispose(); @Override void onEvent(ModelReference reference, IRainbowMessage message); static final String NAME; static final String OPERATION_NAME; static final String CLIENTS_SELECTION; static final String MALICIOUS_CLIENTS_SELECTION; static final String ABOVE_MALICIOUSNESS; static final String HIGH_RT; }