List of usage examples for org.apache.commons.collections4 MapUtils isEmpty
public static boolean isEmpty(final Map<?, ?> map)
From source file:io.cloudslang.lang.compiler.CompileDecisionTest.java
private void validateCompilationArtifact(CompilationArtifact compilationArtifact, List<Input> expectedInputs, List<Output> expectedOutputs, List<Result> expectedResults, Set<String> expectedSystemProperties) { Assert.assertNotNull(compilationArtifact); validateExecutionPlan(compilationArtifact.getExecutionPlan(), expectedInputs, expectedOutputs, expectedResults);/* w w w .jav a2 s . c o m*/ Assert.assertTrue(MapUtils.isEmpty(compilationArtifact.getDependencies())); Assert.assertEquals(expectedInputs, compilationArtifact.getInputs()); Assert.assertEquals(expectedSystemProperties, compilationArtifact.getSystemProperties()); }
From source file:io.cloudslang.lang.compiler.modeller.transformers.DoTransformer.java
private List<RuntimeException> validateRawData(Map<String, Object> rawData) { if (MapUtils.isEmpty(rawData)) { return Collections.singletonList(new RuntimeException("Step has no reference information.")); } else if (rawData.size() > 1) { return Collections.singletonList(new RuntimeException("Step has too many keys under the '" + keyToTransform() + "' keyword,\n" + "May happen due to wrong indentation.")); }//w w w . j av a 2s . c o m executableValidator.validateStepReferenceId(rawData.keySet().iterator().next()); return Collections.emptyList(); }
From source file:com.tongbanjie.tarzan.server.client.ClientManager.java
public ClientChannelInfo pickClientRandomly(String group) { Map<Channel, ClientChannelInfo> map = this.groupChannelTable.get(group); if (MapUtils.isEmpty(map)) { return null; }//from w w w .jav a 2s. co m List<ClientChannelInfo> clientChannelInfoList = new ArrayList<ClientChannelInfo>(map.values()); int size = clientChannelInfoList.size(); return clientChannelInfoList.get(random.nextInt(size)); }
From source file:io.cloudslang.lang.tools.build.tester.SlangTestRunner.java
public void runTestsParallel(String projectPath, Map<String, SlangTestCase> testCases, Map<String, CompilationArtifact> compiledFlows, ThreadSafeRunTestResults runTestsResults) { if (MapUtils.isEmpty(testCases)) { return;//from w ww .ja v a 2 s .co m } printTestForActualRunSummary(TestCaseRunMode.PARALLEL, testCases); testCaseEventDispatchService.unregisterAllListeners(); testCaseEventDispatchService.registerListener(runTestsResults); // for gathering of report data testCaseEventDispatchService.registerListener(loggingSlangTestCaseEventListener); // for logging purpose MultiTriggerTestCaseEventListener multiTriggerTestCaseEventListener = new MultiTriggerTestCaseEventListener(); slang.subscribeOnEvents(multiTriggerTestCaseEventListener, createListenerEventTypesSet()); try { Map<SlangTestCase, Future<?>> testCaseFutures = new LinkedHashMap<>(); for (Map.Entry<String, SlangTestCase> testCaseEntry : testCases.entrySet()) { SlangTestCase testCase = testCaseEntry.getValue(); SlangTestCaseRunnable slangTestCaseRunnable = new SlangTestCaseRunnable(testCase, compiledFlows, projectPath, this, testCaseEventDispatchService, multiTriggerTestCaseEventListener); testCaseFutures.put(testCase, parallelTestCaseExecutorService.submitTestCase(slangTestCaseRunnable)); } final long testCaseTimeoutMinutes = getTestCaseTimeoutInMinutes(); for (Map.Entry<SlangTestCase, Future<?>> slangTestCaseFutureEntry : testCaseFutures.entrySet()) { SlangTestCase testCase = slangTestCaseFutureEntry.getKey(); Future<?> testCaseFuture = slangTestCaseFutureEntry.getValue(); try { testCaseFuture.get(testCaseTimeoutMinutes, MINUTES); } catch (InterruptedException e) { loggingService.logEvent(Level.ERROR, "Interrupted while waiting for result: ", e); } catch (TimeoutException e) { testCaseEventDispatchService.notifyListeners(new FailedSlangTestCaseEvent(testCase, "Timeout reached for test case " + testCase.getName(), e)); } catch (Exception e) { testCaseEventDispatchService .notifyListeners(new FailedSlangTestCaseEvent(testCase, e.getMessage(), e)); } } } finally { testCaseEventDispatchService.unregisterAllListeners(); slang.unSubscribeOnEvents(multiTriggerTestCaseEventListener); } }
From source file:io.cloudslang.lang.tools.build.tester.SlangTestRunner.java
private void printTestForActualRunSummary(TestCaseRunMode runMode, Map<String, SlangTestCase> testCases) { if (!MapUtils.isEmpty(testCases)) { loggingService.logEvent(Level.INFO, "Running " + testCases.size() + " test(s) in " + runMode.toString().toLowerCase(Locale.ENGLISH) + ": "); for (Map.Entry<String, SlangTestCase> stringSlangTestCaseEntry : testCases.entrySet()) { final SlangTestCase slangTestCase = stringSlangTestCaseEntry.getValue(); loggingService.logEvent(Level.INFO, PREFIX_DASH + SlangTestCase.generateTestCaseReference(slangTestCase)); }//ww w .j a v a2s . co m } }
From source file:com.jkoolcloud.tnt4j.streams.configure.zookeeper.ZKConfigManager.java
/** * Opens ZK ensemble connection using configuration properties defined values. * * @param zkConfProps/* w w w .j a va 2 s . com*/ * streams ZooKeeper configuration properties * @return instance of opened ZK connection * @throws IOException * if I/O exception occurs while initializing ZooKeeper connection * @throws InterruptedException * if the current thread is interrupted while waiting */ public static ZKConnection openConnection(Properties zkConfProps) throws IOException, InterruptedException { LOGGER.log(OpLevel.DEBUG, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigManager.connecting")); if (MapUtils.isEmpty(zkConfProps)) { LOGGER.log(OpLevel.DEBUG, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigManager.empty.cfg.props")); } conn = new ZKConnection(); String zkConnStr = zkConfProps.getProperty(PROP_ZK_CONN, DEFAULT_CONN_HOST); int timeout = Integer .parseInt(zkConfProps.getProperty(PROP_ZK_CONN_TIMEOUT, String.valueOf(DEFAULT_CONN_TIMEOUT))); conn.connect(zkConnStr, timeout); // NON-NLS LOGGER.log(OpLevel.DEBUG, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ZKConfigManager.connected"), zkConnStr); return conn; }
From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java
private Map<String, Object> getActionRawData(Map<String, Object> executableRawData, List<RuntimeException> errors, ParsedSlang parsedSlang, String execName) { Map<String, Object> actionRawData = new HashMap<>(); Object javaActionRawData = executableRawData.get(SlangTextualKeys.JAVA_ACTION_KEY); Object pythonActionRawData = executableRawData.get(SlangTextualKeys.PYTHON_ACTION_KEY); Object seqActionRawData = executableRawData.get(SlangTextualKeys.SEQ_ACTION_KEY); if (javaActionRawData != null) { actionRawData.put(SlangTextualKeys.JAVA_ACTION_KEY, executableRawData.get(SlangTextualKeys.JAVA_ACTION_KEY)); }//from www . j ava2 s. co m if (pythonActionRawData != null) { actionRawData.put(SlangTextualKeys.PYTHON_ACTION_KEY, executableRawData.get(SlangTextualKeys.PYTHON_ACTION_KEY)); } if (seqActionRawData != null) { actionRawData.put(SlangTextualKeys.SEQ_ACTION_KEY, executableRawData.get(SlangTextualKeys.SEQ_ACTION_KEY)); } if (MapUtils.isEmpty(actionRawData)) { errors.add(new RuntimeException("Error compiling " + parsedSlang.getName() + ". Operation: " + execName + " has no action data")); } return actionRawData; }
From source file:monasca.api.infrastructure.persistence.hibernate.AlarmDefinitionSqlRepoImpl.java
private void updateChangedSubAlarms(final Map<String, AlarmSubExpression> changedSubAlarms, final Session session) { if (!MapUtils.isEmpty(changedSubAlarms)) for (Map.Entry<String, AlarmSubExpression> entry : changedSubAlarms.entrySet()) { final AlarmSubExpression sa = entry.getValue(); final String subAlarmDefinitionId = entry.getKey(); SubAlarmDefinitionDb subAlarmDefinitionDb = session.get(SubAlarmDefinitionDb.class, subAlarmDefinitionId); subAlarmDefinitionDb.setOperator(sa.getOperator().name()); subAlarmDefinitionDb.setThreshold(sa.getThreshold()); subAlarmDefinitionDb.setUpdatedAt(this.getUTCNow()); subAlarmDefinitionDb.setDeterministic(sa.isDeterministic()); session.saveOrUpdate(subAlarmDefinitionDb); }/*from ww w . j a v a 2s.c o m*/ }
From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java
private StepModellingResult compileStep(String stepName, Map<String, Object> stepRawData, String defaultSuccess, Map<String, String> imports, String defaultFailure, String namespace, String onFailureStepName, boolean onFailureSection, SensitivityLevel sensitivityLevel) { List<RuntimeException> errors = new ArrayList<>(); if (MapUtils.isEmpty(stepRawData)) { stepRawData = new HashMap<>(); errors.add(new RuntimeException("Step: " + stepName + " has no data")); }//from w w w . ja v a 2 s. co m final boolean isExternal = stepRawData.containsKey(DO_EXTERNAL_KEY); final List<Transformer> localPreStepTransformers = isExternal ? externalPreStepTransformers : preStepTransformers; final List<Transformer> localPostStepTransformers = isExternal ? externalPostStepTransformers : postStepTransformers; Map<String, Serializable> preStepData = new HashMap<>(); Map<String, Serializable> postStepData = new HashMap<>(); errors.addAll(preCompileValidator.checkKeyWords(stepName, "", stepRawData, ListUtils.union(localPreStepTransformers, localPostStepTransformers), stepAdditionalKeyWords, null)); String errorMessagePrefix = "For step '" + stepName + "' syntax is illegal.\n"; preStepData.putAll(transformersHandler.runTransformers(stepRawData, localPreStepTransformers, errors, errorMessagePrefix, sensitivityLevel)); postStepData.putAll(transformersHandler.runTransformers(stepRawData, localPostStepTransformers, errors, errorMessagePrefix, sensitivityLevel)); replaceOnFailureReference(postStepData, onFailureStepName); String workerGroup = (String) stepRawData.get(SlangTextualKeys.WORKER_GROUP); String refId = ""; final List<Argument> arguments = getArgumentsFromDoStep(preStepData); final Map<String, Object> doRawData = getRawDataFromDoStep(stepRawData); if (MapUtils.isNotEmpty(doRawData)) { try { String refString = doRawData.keySet().iterator().next(); refId = resolveReferenceId(refString, imports, namespace, preStepData); } catch (RuntimeException rex) { errors.add(rex); } } List<Map<String, String>> navigationStrings = getNavigationStrings(postStepData, defaultSuccess, defaultFailure, errors); Step step = createStep(stepName, onFailureSection, preStepData, postStepData, arguments, workerGroup, refId, navigationStrings); return new StepModellingResult(step, errors); }
From source file:monasca.api.infrastructure.persistence.hibernate.AlarmDefinitionSqlRepoImpl.java
private void createSubExpressions(Session session, AlarmDefinitionDb alarmDefinition, Map<String, AlarmSubExpression> alarmSubExpressions) { if (alarmSubExpressions != null) { for (Map.Entry<String, AlarmSubExpression> subEntry : alarmSubExpressions.entrySet()) { String subAlarmId = subEntry.getKey(); AlarmSubExpression subExpr = subEntry.getValue(); MetricDefinition metricDef = subExpr.getMetricDefinition(); // Persist sub-alarm final DateTime now = this.getUTCNow(); final SubAlarmDefinitionDb subAlarmDefinitionDb = new SubAlarmDefinitionDb(subAlarmId, alarmDefinition, subExpr.getFunction().name(), metricDef.name, subExpr.getOperator().name(), subExpr.getThreshold(), subExpr.getPeriod(), subExpr.getPeriods(), now, now, subExpr.isDeterministic()); session.save(subAlarmDefinitionDb); // Persist sub-alarm dimensions if (!MapUtils.isEmpty(metricDef.dimensions)) { SubAlarmDefinitionDimensionDb definitionDimension; SubAlarmDefinitionDimensionId definitionDimensionId; for (Map.Entry<String, String> dimEntry : metricDef.dimensions.entrySet()) { definitionDimensionId = new SubAlarmDefinitionDimensionId(subAlarmDefinitionDb, dimEntry.getKey()); definitionDimension = new SubAlarmDefinitionDimensionDb(definitionDimensionId, dimEntry.getValue()); session.save(definitionDimension); }/* ww w . j a v a 2s . c o m*/ } } } }