List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.vmware.photon.controller.api.client.resource.DeploymentApiTest.java
@Test public void testGetVmsAsync() throws IOException, InterruptedException { Vm vm1 = new Vm(); vm1.setId("vm1"); Vm vm2 = new Vm(); vm2.setId("vm2"); final ResourceList<Vm> vmList = new ResourceList<>(Arrays.asList(vm1, vm2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(vmList); setupMocks(serializedTask, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentApi(restClient); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.getAllDeploymentVmsAsync("foo", new FutureCallback<ResourceList<Vm>>() { @Override/* w ww .j a v a 2 s . c om*/ public void onSuccess(ResourceList<Vm> result) { assertEquals(result.getItems(), vmList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentRestApiTest.java
@Test public void testGetVmsAsync() throws IOException, InterruptedException { Vm vm1 = new Vm(); vm1.setId("vm1"); Vm vm2 = new Vm(); vm2.setId("vm2"); final ResourceList<Vm> vmList = new ResourceList<>(Arrays.asList(vm1, vm2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(vmList); setupMocks(serializedTask, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.getAllDeploymentVmsAsync("foo", new FutureCallback<ResourceList<Vm>>() { @Override/* www . j av a 2 s .c o m*/ public void onSuccess(ResourceList<Vm> result) { assertEquals(result.getItems(), vmList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:edu.pitt.dbmi.facebase.hd.InstructionQueueManager.java
/** Tell's Hub DB about the results of the queue processing effort * Called after processing of the queue item and construction of the TrueCrypt volume is complete. * Tells Hub where TrueCrypt volume is located, when processing finished, and any error reporting; sets status * Sets status='complete' or status='error' in fb_queue row for this queue item * Sets Completed=unixEpicTime in fb_queue row for this queue item * Sets results=ComplexJSONstring holding path, logs, messages. That string would look like this: * <pre>/*from w w w . j ava 2 s .co m*/ * { * "path": "/path/to/file/3DData1-2-11-35username.tc", * "log": "", * "messages": [ * "File 1102.obj was not found and not included in your zip file.", * "Blah blah blah" * ] * } * <pre> * * @param trueCryptFilename the full path name of the trueCrypt file (ie. /var/downloads/FBdata.tc) * @param size total size of TrueCrypt file * @param qid the queue id of the item that was processed * @param errors list of human-readable errors that were encountered (if nonzero, the status will be set to "error", otherwise status="complete". * @param logs list of detailed error information that was gathered (usually with Exception.getMessage()). * @return true if successful */ boolean updateInstructionToCompleted(String trueCryptFilename, long size, long qid, ArrayList<String> errors, ArrayList<String> logs) { log.debug("InstructionQueueManager.updateInstructionToCompleted() called."); Session session = null; Transaction transaction = null; long unixEpicTime = System.currentTimeMillis() / 1000L; try { session = conf.openSession(); transaction = session.beginTransaction(); List<InstructionQueueItem> items = getPendingQueueItems(session, qid); String sizeString = (new Long(size)).toString(); //LIKE THIS: jsonResultsString = "{\"path\":\""+trueCryptFilename+"\",\"log\":\"\",\"messages\":[\""+errorsString+"\"],\"size\":\""+sizeString+"\"}"; Map resultsJSON = new LinkedHashMap(); resultsJSON.put("path", trueCryptFilename); resultsJSON.put("size", sizeString); JSONArray messagesJSON = new JSONArray(); JSONArray logsJSON = new JSONArray(); for (String message : errors) { messagesJSON.add(message); } resultsJSON.put("messages", messagesJSON); for (String log : logs) { logsJSON.add(log); } resultsJSON.put("log", logsJSON); //LIKE THIS: jsonResultsString = resultsJSON.toString();...but toString() won't work...need toJSONString(): String jsonResultsString = JSONValue.toJSONString(resultsJSON); if (items != null && items.size() >= 1) { InstructionQueueItem item = items.get(0); if (errors.isEmpty()) { item.setStatus("complete"); } else { item.setStatus("error"); } item.setResults(jsonResultsString); item.setCompleted(unixEpicTime); session.update(item); transaction.commit(); } session.close(); return true; } catch (Throwable t) { String errorString = "InstructionQueueManager caught a t in updateInstructionsToCompleted()" + t.toString(); String logString = t.getMessage(); edu.pitt.dbmi.facebase.hd.HumanDataController.addError(errorString, logString); log.error(errorString, t); handleThrowable(t, session, transaction); } return false; }
From source file:com.dilmus.dilshad.scabi.core.DComputeRun.java
public void run() { m_isDone = false;// ww w . ja v a2 s .c o m if (true == m_isError) m_retriesTillNow = m_retriesTillNow + 1; m_isError = false; synchronized (m_computeSync) { try { m_computeSync.setTU(m_TU); m_computeSync.setSU(m_SU); doRun(); } catch (Throwable e) { log.debug("run() Throwable : {}", e.toString()); // m_computeSync is faulty only in the case of ClientProtocolException/NetworkException which // is already handled in doRun() method // // // m_computeSync.setFaulty(true); // TODO: check later, low priority, whether to use m_SU int splitno = m_computeSync.getSU(); // just to be exact, getting SU directly from m_computeSync log.debug("run() m_computeSync.getSU() : {}", splitno); String errorJson = DMJson.error(DMUtil.clientErrMsg(e)); synchronized (m_config) { // Not used m_config.setOrIncFailedSplitRetryMap(splitno); // Not used m_config.setSplitStatus(splitno, false); m_config.setResult(splitno, errorJson); } } } m_isDone = true; m_isRetrySubmitted = false; if (false == m_isRunOnce) { m_isRunOnce = true; } }
From source file:aiai.ai.launchpad.server.ServerController.java
private UploadResult uploadResource(MultipartFile file, Long taskId) { String originFilename = file.getOriginalFilename(); if (originFilename == null) { return new UploadResult(false, "#442.01 name of uploaded file is null"); }//from www . jav a 2s . c om if (taskId == null) { return new UploadResult(false, "#442.87 taskId is null"); } Task task = taskRepository.findById(taskId).orElse(null); if (task == null) { return new UploadResult(false, "#442.83 taskId is null"); } final TaskParamYaml taskParamYaml = taskParamYamlUtils.toTaskYaml(task.getParams()); try { File tempDir = DirUtils.createTempDir("upload-resource-"); if (tempDir == null || tempDir.isFile()) { final String location = System.getProperty("java.io.tmpdir"); return new UploadResult(false, "#442.04 can't create temporary directory in " + location); } final File resFile = new File(tempDir, "resource."); log.debug("Start storing an uploaded resource data to disk"); try (OutputStream os = new FileOutputStream(resFile)) { IOUtils.copy(file.getInputStream(), os, 64000); } try (InputStream is = new FileInputStream(resFile)) { binaryDataService.save(is, resFile.length(), Enums.BinaryDataType.DATA, taskParamYaml.outputResourceCode, taskParamYaml.outputResourceCode, false, null); } } catch (Throwable th) { log.error("Error", th); return new UploadResult(false, "#442.05 can't load snippets, Error: " + th.toString()); } task.resultReceived = true; taskRepository.save(task); return OK_UPLOAD_RESULT; }
From source file:com.mendhak.gpslogger.common.PrefsIO.java
public void ImportFile() { SharedPreferences.Editor editor = sharedPrefs.edit(); String str = ""; String[] params;//w w w .j av a 2 s. c o m String regexp = "[" + separator + "]"; int imported = 0; Utilities.LogDebug("Trying to import settings from file: " + curFileName); if (curFileName.length() > 0) { File mySetFile = new File(curFileName); try { if (mySetFile.exists()) { FileReader fr = new FileReader(mySetFile); BufferedReader br = new BufferedReader(fr); while ((str = br.readLine()) != null) { if (str.startsWith(commentPrefix)) continue; params = str.split(regexp); if (params.length < 3) continue; if (params[2].endsWith(strBoolean)) editor.putBoolean(params[0], Boolean.parseBoolean(params[1])); else if (params[2].endsWith(strString)) editor.putString(params[0], DecodeValue(params[1])); editor.commit(); imported++; } br.close(); Utilities.LogDebug("Finished import: " + imported + " lines"); Toast.makeText(context, R.string.ImportSuccess, Toast.LENGTH_LONG).show(); Intent settingsActivity = new Intent(context, GpsSettingsActivity.class); context.startActivity(settingsActivity); } else Toast.makeText(context, R.string.ImportFailed, Toast.LENGTH_LONG).show(); } catch (Throwable t) { Toast.makeText(context, "Exception: " + t.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.ImportFailed, Toast.LENGTH_LONG).show(); } } else Toast.makeText(context, R.string.ImportFailed, Toast.LENGTH_LONG).show(); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentApiTest.java
@Test public void testListAllAsyncForPagination() throws Exception { Deployment deployment = getNewDeployment(); Deployment deploymentNextPage = getNewDeployment(); String nextPageLink = "nextPageLink"; ResourceList<Deployment> deploymentResourceList = new ResourceList<>(Arrays.asList(deployment), nextPageLink, null);/*from w ww . j ava 2s . c o m*/ ResourceList<Deployment> deploymentResourceListNextPage = new ResourceList<>( Arrays.asList(deploymentNextPage)); ObjectMapper mapper = new ObjectMapper(); String serializedResponse = mapper.writeValueAsString(deploymentResourceList); String serializedResponseNextPage = mapper.writeValueAsString(deploymentResourceListNextPage); setupMocksForPagination(serializedResponse, serializedResponseNextPage, nextPageLink, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentApi(restClient); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.listAllAsync(new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { assertEquals(result.getItems().size(), deploymentResourceList.getItems().size() + deploymentResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(deploymentResourceList.getItems())); assertTrue(result.getItems().containsAll(deploymentResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentRestApiTest.java
@Test public void testListAllAsyncForPagination() throws Exception { Deployment deployment = getNewDeployment(); Deployment deploymentNextPage = getNewDeployment(); String nextPageLink = "nextPageLink"; ResourceList<Deployment> deploymentResourceList = new ResourceList<>(Arrays.asList(deployment), nextPageLink, null);//ww w . java2s . c o m ResourceList<Deployment> deploymentResourceListNextPage = new ResourceList<>( Arrays.asList(deploymentNextPage)); ObjectMapper mapper = new ObjectMapper(); String serializedResponse = mapper.writeValueAsString(deploymentResourceList); String serializedResponseNextPage = mapper.writeValueAsString(deploymentResourceListNextPage); setupMocksForPagination(serializedResponse, serializedResponseNextPage, nextPageLink, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.listAllAsync(new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { assertEquals(result.getItems().size(), deploymentResourceList.getItems().size() + deploymentResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(deploymentResourceList.getItems())); assertTrue(result.getItems().containsAll(deploymentResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.mendhak.gpslogger.common.PrefsIO.java
public void ExportFile() { Object val = null; String str = ""; String type = "unknown"; String value = ""; int ind = 0;//from ww w . j av a 2 s. c o m Date date = new Date(); String strdate; SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); strdate = dateformat.format(date); Utilities.LogDebug("Trying to export settings to file: " + curFileName); File mySetFile = new File(curFileName); try { if (!mySetFile.exists()) mySetFile.createNewFile(); else { // Toast.makeText(context, R.string.ExportFailed, Toast.LENGTH_LONG).show(); Utilities.LogDebug("File exists, asking another filename"); ReAskFileName(); return; } FileWriter fw = new FileWriter(mySetFile); PrintWriter pw = new PrintWriter(fw); Map<String, ?> prefsMap = sharedPrefs.getAll(); pw.println(commentPrefix + " Settings Dump " + strdate); pw.println(commentPrefix + version); for (Map.Entry<String, ?> entry : prefsMap.entrySet()) { val = entry.getValue(); value = val.toString(); str = ""; str += val.getClass(); ind = str.lastIndexOf("."); if (ind > 0) type = str.substring(ind + 1); if (type.endsWith("String")) pw.println(entry.getKey() + separator + EncodeValue(value) + separator + type); else pw.println(entry.getKey() + separator + value + separator + type); } pw.close(); fw.close(); Toast.makeText(context, R.string.ExportSuccess, Toast.LENGTH_LONG).show(); } catch (Throwable t) { Toast.makeText(context, "Exception: " + t.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.ExportFailed, Toast.LENGTH_LONG).show(); } }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentApiTest.java
@Test public void testGetVmsAsyncForPagination() throws IOException, InterruptedException { Vm vm1 = new Vm(); vm1.setId("vm1"); Vm vm2 = new Vm(); vm2.setId("vm2"); Vm vm3 = new Vm(); vm3.setId("vm3"); String nextPageLink = "nextPageLink"; final ResourceList<Vm> vmList = new ResourceList<>(Arrays.asList(vm1, vm2), nextPageLink, null); final ResourceList<Vm> vmListNextPage = new ResourceList<>(Arrays.asList(vm3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(vmList); String serializedTaskNextPage = mapper.writeValueAsString(vmListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentApi(restClient); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.getAllDeploymentVmsAsync("foo", new FutureCallback<ResourceList<Vm>>() { @Override// w w w . ja v a 2s . c o m public void onSuccess(ResourceList<Vm> result) { assertEquals(result.getItems().size(), vmList.getItems().size() + vmListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(vmList.getItems())); assertTrue(result.getItems().containsAll(vmListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }