/** * @return a {@link Version} initialized with this {@code MemberVersion}'s major.minor version. */ public Version asVersion() { return Version.of(major, minor); } }
/** * @return a {@link Version} initialized with this {@code MemberVersion}'s major.minor version. */ public Version asVersion() { return Version.of(major, minor); } }
/** * Parse the given string to a {@code Version}. This method may throw an {@code IllegalArgumentException} * * @param version string to parse to {@code Version}. * @return the {@code Version} parsed from given argument. */ public static Version of(String version) { String[] tokens = StringUtil.tokenizeVersionString(version); if (tokens != null && tokens.length >= 2) { return Version.of(Byte.valueOf(tokens[0]), Byte.valueOf(tokens[1])); } else { throw new IllegalArgumentException("Cannot parse " + version + " to ClusterVersion."); } }
/** * Parse the given string to a {@code Version}. This method may throw an {@code IllegalArgumentException} * * @param version string to parse to {@code Version}. * @return the {@code Version} parsed from given argument. */ public static Version of(String version) { String[] tokens = StringUtil.tokenizeVersionString(version); if (tokens != null && tokens.length >= 2) { return Version.of(Byte.valueOf(tokens[0]), Byte.valueOf(tokens[1])); } else { throw new IllegalArgumentException("Cannot parse " + version + " to ClusterVersion."); } }
private void handleChangeClusterVersion(HttpPostCommand command) throws UnsupportedEncodingException { byte[] data = command.getData(); String[] strList = bytesToString(data).split("&"); String groupName = URLDecoder.decode(strList[0], "UTF-8"); String groupPass = URLDecoder.decode(strList[1], "UTF-8"); String versionParam = URLDecoder.decode(strList[2], "UTF-8"); String res; try { Node node = textCommandService.getNode(); ClusterService clusterService = node.getClusterService(); GroupConfig groupConfig = node.getConfig().getGroupConfig(); if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) { res = response(ResponseType.FORBIDDEN); } else { Version version = Version.of(versionParam); clusterService.changeClusterVersion(version); res = response(ResponseType.SUCCESS, "version", clusterService.getClusterVersion().toString()); } } catch (Throwable throwable) { logger.warning("Error occurred while changing cluster version", throwable); res = exceptionResponse(throwable); } command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res)); }
clusterVersion = Version.of(jsonClusterVersion);
clusterVersion = Version.of(jsonClusterVersion);
private void handleChangeClusterVersion(HttpPostCommand command) throws UnsupportedEncodingException { byte[] data = command.getData(); String[] strList = bytesToString(data).split("&"); String res; try { Node node = textCommandService.getNode(); ClusterService clusterService = node.getClusterService(); if (authenticate(command, strList[0], strList.length > 1 ? strList[1] : null)) { String versionParam = URLDecoder.decode(strList[2], "UTF-8"); Version version = Version.of(versionParam); clusterService.changeClusterVersion(version); res = response(ResponseType.SUCCESS, "version", clusterService.getClusterVersion().toString()); } else { res = response(ResponseType.FORBIDDEN); } } catch (Throwable throwable) { logger.warning("Error occurred while changing cluster version", throwable); res = exceptionResponse(throwable); } command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res)); }