@Override public void run() { try { org.batfish.coordinator.Main.main(argArray, _logger, bindPortFutures); } catch (Exception e) { _logger.errorf( "Initialization of coordinator failed with args: %s\nExceptionMessage: %s\n", Arrays.toString(argArray), e.getMessage()); } } };
private boolean isDeltaReady() { if (!_settings.getSanityCheck()) { return true; } if (_currDeltaTestrig == null) { _logger.errorf("Active delta snapshot is not set\n"); return false; } return true; }
@Override public void run() { try { org.batfish.main.Driver.main(argArray, _logger); } catch (Exception e) { _logger.errorf( "Initialization of batfish failed with args: %s\nExceptionMessage: %s\n", Arrays.toString(argArray), e.getMessage()); } } };
private boolean isSetContainer(boolean printError) { if (!_settings.getSanityCheck()) { return true; } if (_currContainerName == null) { if (printError) { _logger.errorf("Active network is not set\n"); } return false; } return true; }
private boolean isSetTestrig() { if (!_settings.getSanityCheck()) { return true; } if (_currTestrig == null) { _logger.errorf("Active snapshot is not set.\n"); _logger.errorf( "Specify snapshot on command line (-%s <snapshotdir>) or use command (%s <snapshotdir>)\n", Settings.ARG_SNAPSHOT_DIR, Command.INIT_SNAPSHOT.commandName()); return false; } return true; }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String filename = file.getFileName().toString(); if (filename.endsWith(".json")) { try { readQuestionTemplate(file, templates); } catch (Exception e) { _logger.errorf( "Failed to read question template from '%s': %s", file, Throwables.getStackTraceAsString(e)); } } return FileVisitResult.CONTINUE; } });
private boolean cat(String[] words) throws IOException { if (words.length != 2) { _logger.errorf("Invalid arguments: %s\n", Arrays.toString(words)); printUsage(Command.CAT); return false; } String filename = words[1]; try (BufferedReader br = new BufferedReader(new FileReader(filename))) { String line = null; while ((line = br.readLine()) != null) { _logger.outputf("%s\n", line); } } return true; }
private static void checkParentProcess(int ppid) { try { if (!isProcessRunning(ppid)) { _mainLogger.infof("Committing suicide; ppid %d is dead.\n", ppid); System.exit(0); } } catch (Exception e) { _mainLogger.errorf("Exception while checking parent process with pid: %s", ppid); } }
private void checkTasks() { try { List<QueuedWork> workToCheck = _workQueueMgr.getWorkForChecking(); for (QueuedWork work : workToCheck) { String assignedWorker = work.getAssignedWorker(); if (assignedWorker == null) { _logger.errorf("WM:CheckWork no assigned worker for %s\n", work); _workQueueMgr.makeWorkUnassigned(work); continue; } checkTask(work, assignedWorker); } } catch (Exception e) { _logger.errorf("Got exception in checkTasks: %s\n", Throwables.getStackTraceAsString(e)); } }
@GET @Path(CoordConsts.SVC_RSC_POOL_GETSTATUS) @Produces(MediaType.APPLICATION_JSON) public JSONArray getStatus() { try { _logger.info("PMS:getStatus\n"); Map<String, String> poolStatus = Main.getPoolMgr().getPoolStatus(); JSONObject obj = new JSONObject(poolStatus); return new JSONArray(Arrays.asList(CoordConsts.SVC_KEY_SUCCESS, obj.toString())); } catch (Exception e) { _logger.errorf("PMS:getStatus exception: %s\n", Throwables.getStackTraceAsString(e)); return new JSONArray(Arrays.asList(CoordConsts.SVC_KEY_FAILURE, e.getMessage())); } }
private boolean setBatfishLogLevel(List<String> options, List<String> parameters) { if (!isValidArgument(options, parameters, 0, 1, 1, Command.SET_BATFISH_LOGLEVEL)) { return false; } String logLevelStr = parameters.get(0).toLowerCase(); if (!BatfishLogger.isValidLogLevel(logLevelStr)) { _logger.errorf("Undefined loglevel value: %s\n", logLevelStr); return false; } _settings.setBatfishLogLevel(logLevelStr); _logger.outputf("Changed batfish loglevel to %s\n", logLevelStr); return true; }
/** Gets the {@link ReferenceLibrary} for the network */ @Override public ReferenceLibrary getReferenceLibraryData() { Path libraryPath = _settings .getStorageBase() .resolve(_settings.getContainer().getId()) .resolve(BfConsts.RELPATH_REFERENCE_LIBRARY_PATH); try { return ReferenceLibrary.read(libraryPath); } catch (IOException e) { _logger.errorf("Could not read reference library data from %s: %s", libraryPath, e); return null; } }
@GET @Path(CoordConsts.SVC_RSC_GETSTATUS) @Produces(MediaType.APPLICATION_JSON) public JSONArray getStatus() { try { _logger.info("WMS:getStatus\n"); JSONObject retObject = Main.getWorkMgr().getStatusJson(); retObject.put("service-version", Version.getVersion()); return successResponse(retObject); } catch (Exception e) { String stackTrace = Throwables.getStackTraceAsString(e); _logger.errorf("WMS:getStatus exception: %s", stackTrace); return failureResponse(e.getMessage()); } }
private boolean showVersion(List<String> options, List<String> parameters) { if (!isValidArgument(options, parameters, 0, 0, 0, Command.SHOW_VERSION)) { return false; } _logger.outputf("Client version is %s\n", Version.getVersion()); Map<String, String> map = _workHelper.getInfo(); if (!map.containsKey(CoordConsts.SVC_KEY_VERSION)) { _logger.errorf("key '%s' not found in Info\n", CoordConsts.SVC_KEY_VERSION); return false; } String version = map.get(CoordConsts.SVC_KEY_VERSION); _logger.outputf("Service version is %s\n", version); return true; }
private boolean setLogLevel(List<String> options, List<String> parameters) { if (!isValidArgument(options, parameters, 0, 1, 1, Command.SET_LOGLEVEL)) { return false; } String logLevelStr = parameters.get(0).toLowerCase(); if (!BatfishLogger.isValidLogLevel(logLevelStr)) { _logger.errorf("Undefined loglevel value: %s\n", logLevelStr); return false; } _logger.setLogLevel(logLevelStr); _settings.setLogLevel(logLevelStr); _logger.outputf("Changed client loglevel to %s\n", logLevelStr); return true; }
public boolean killWork(QueuedWork work) { String worker = work.getAssignedWorker(); if (worker != null) { return killWork(work, worker); } // (worker = null) => this work was not assigned in the first place boolean killed = false; Task fakeTask = new Task(TaskStatus.TerminatedByUser, "Killed unassigned work"); try { _workQueueMgr.processTaskCheckResult(work, fakeTask); killed = true; } catch (Exception e) { _logger.errorf("exception: %s\n", Throwables.getStackTraceAsString(e)); } return killed; }
@GET @Produces(MediaType.APPLICATION_JSON) public JSONArray getInfo() { _logger.info("WMS:getInfo\n"); try { JSONObject map = new JSONObject(); map.put("Service name", "Batfish coordinator"); map.put(CoordConsts.SVC_KEY_VERSION, Version.getVersion()); map.put("APIs", "Enter ../application.wadl (relative to your URL) to see supported methods"); return successResponse(map); } catch (Exception e) { String stackTrace = Throwables.getStackTraceAsString(e); _logger.errorf("WMS:getInfo exception: %s", stackTrace); return failureResponse(e.getMessage()); } }
private void computeAndStoreCompletionMetadata(Map<String, Configuration> configurations) { try { _storage.storeCompletionMetadata( computeCompletionMetadata(configurations), _settings.getContainer(), _testrigSettings.getName()); } catch (IOException e) { _logger.errorf("Error storing CompletionMetadata: %s", e); } }
BfCoordWorkHelper(BatfishLogger logger, Settings settings) { _logger = logger; _settings = settings; _coordWorkMgr = _settings.getCoordinatorHost() + ":" + _settings.getCoordinatorWorkPort(); _coordWorkMgrV2 = _settings.getCoordinatorHost() + ":" + _settings.getCoordinatorWorkV2Port(); try { _client = getClientBuilder().build(); } catch (Exception e) { _logger.errorf("exception: "); _logger.error(Throwables.getStackTraceAsString(e) + "\n"); throw new BatfishException("Failed to create HTTP client", e); } }
boolean queueWork(WorkItem wItem) { try { WebTarget webTarget = getTarget(CoordConsts.SVC_RSC_QUEUE_WORK); MultiPart multiPart = new MultiPart(); multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE); addTextMultiPart( multiPart, CoordConsts.SVC_KEY_WORKITEM, BatfishObjectMapper.writeString(wItem)); addTextMultiPart(multiPart, CoordConsts.SVC_KEY_API_KEY, _settings.getApiKey()); JSONObject jObj = postData(webTarget, multiPart); return jObj != null; } catch (Exception e) { _logger.errorf("exception: "); _logger.error(Throwables.getStackTraceAsString(e) + "\n"); return false; } }