@Override public int execute(String[] operationArgs) throws Exception { UpdateOperationOptions operationOptions = parseOptions(operationArgs); UpdateOperationResult operationResult = new UpdateOperation(config, operationOptions).execute(); printResults(operationResult); return 0; }
private String getAppInfoResponseStr() throws Exception { boolean hasGuiPlugin = Plugins.get(GUI_PLUGIN_ID) != null; String typeStr = determineType(hasGuiPlugin); String distStr = determineDist(hasGuiPlugin, typeStr); String snapshotsEnabled = (options.isSnapshots()) ? "true" : "false"; String osStr = EnvironmentUtil.getOperatingSystemDescription(); String archStr = EnvironmentUtil.getArchDescription(); String apiEndpointUrl = (options.getApiEndpoint() != null) ? options.getApiEndpoint() : API_DEFAULT_ENDPOINT_URL; URL appListUrl = new URL(String.format(API_APP_LIST_REQUEST_FORMAT, apiEndpointUrl, distStr, typeStr, snapshotsEnabled, osStr, archStr)); logger.log(Level.INFO, "Querying " + appListUrl + " ..."); eventBus.post(new ConnectToHostExternalEvent(appListUrl.getHost())); URLConnection urlConnection = appListUrl.openConnection(); urlConnection.setConnectTimeout(2000); urlConnection.setReadTimeout(2000); BufferedReader urlStreamReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); StringBuilder responseStringBuilder = new StringBuilder(); String line; while ((line = urlStreamReader.readLine()) != null) { responseStringBuilder.append(line); } String responseStr = responseStringBuilder.toString(); logger.log(Level.INFO, "Response from api.syncany.org: " + responseStr); return responseStr; }
@Override public UpdateOperationResult execute() throws Exception { result.setAction(options.getAction()); switch (options.getAction()) { case CHECK: return executeCheck(); default: throw new Exception("Unknown action: " + options.getAction()); } }
private UpdateOperationResult executeCheck() throws Exception { Version localAppVersion = Version.valueOf(Client.getApplicationVersion()); String appInfoResponseStr = getAppInfoResponseStr(); AppInfoResponse appInfoResponse = new Persister().read(AppInfoResponse.class, appInfoResponseStr); ArrayList<AppInfo> appInfoList = appInfoResponse.getAppInfoList(); if (appInfoList.size() > 0) { AppInfo remoteAppInfo = appInfoList.get(0); Version remoteAppVersion = Version.valueOf(remoteAppInfo.getAppVersion()); boolean newVersionAvailable = remoteAppVersion.greaterThan(localAppVersion); result.setResultCode(UpdateResultCode.OK); result.setAppInfo(remoteAppInfo); result.setNewVersionAvailable(newVersionAvailable); return result; } else { result.setResultCode(UpdateResultCode.NOK); return result; } }
public UpdateOperationResult update(UpdateOperationOptions options) throws Exception { return new UpdateOperation(config, options).execute(); }
@Override public void run() { try { UpdateOperation updateOperation = new UpdateOperation(null, concreteRequest.getOptions()); UpdateOperationResult operationResult = updateOperation.execute(); switch (operationResult.getResultCode()) { case OK: eventBus.post(new UpdateManagementResponse(UpdateManagementResponse.OK, operationResult, request.getId())); break; case NOK: eventBus.post(new UpdateManagementResponse(UpdateManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId())); break; } } catch (Exception e) { logger.log(Level.WARNING, "Error executing update management request.", e); eventBus.post(new UpdateManagementResponse(UpdateManagementResponse.NOK_OPERATION_FAILED, new UpdateOperationResult(), request.getId())); } } }, "UpdRq/" + concreteRequest.getOptions().getAction());