Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
, like most MySQL Connectors.
There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
this software, see the FLOSS License Exception
.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; version 2
of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
Floor, Boston, MA 02110-1301 USA
*/
package com.mysql.fabric.proto.xmlrpc;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.mysql.fabric.FabricCommunicationException;
import com.mysql.fabric.FabricStateResponse;
import com.mysql.fabric.Response;
import com.mysql.fabric.Server;
import com.mysql.fabric.ServerGroup;
import com.mysql.fabric.ServerMode;
import com.mysql.fabric.ServerRole;
import com.mysql.fabric.ShardIndex;
import com.mysql.fabric.ShardMapping;
import com.mysql.fabric.ShardMappingFactory;
import com.mysql.fabric.ShardTable;
import com.mysql.fabric.ShardingType;
/**
* Fabric client using the XML-RPC protocol.
*/
public class XmlRpcClient {
// name used to identify client to Fabric server for error reports
private static final String THREAT_REPORTER_NAME = "MySQL Connector/J";
// method names
private static final String METHOD_DUMP_FABRIC_NODES = "dump.fabric_nodes";
private static final String METHOD_DUMP_SERVERS = "dump.servers";
private static final String METHOD_DUMP_SHARD_TABLES = "dump.shard_tables";
private static final String METHOD_DUMP_SHARD_INDEX = "dump.shard_index";
private static final String METHOD_DUMP_SHARD_MAPS = "dump.shard_maps";
private static final String METHOD_SHARDING_LOOKUP_SERVERS = "sharding.lookup_servers";
private static final String METHOD_SHARDING_CREATE_DEFINITION = "sharding.create_definition";
private static final String METHOD_SHARDING_ADD_TABLE = "sharding.add_table";
private static final String METHOD_SHARDING_ADD_SHARD = "sharding.add_shard";
private static final String METHOD_GROUP_LOOKUP_GROUPS = "group.lookup_groups";
private static final String METHOD_GROUP_CREATE = "group.create";
private static final String METHOD_GROUP_ADD = "group.add";
private static final String METHOD_GROUP_PROMOTE = "group.promote";
private static final String METHOD_GROUP_DESTROY = "group.destroy";
private static final String METHOD_THREAT_REPORT_ERROR = "threat.report_error";
private static final String METHOD_THREAT_REPORT_FAILURE = "threat.report_failure";
// field names for Fabric result sets
private static final String FIELD_MODE = "mode";
private static final String FIELD_STATUS = "status";
private static final String FIELD_HOST = "host";
private static final String FIELD_PORT = "port";
private static final String FIELD_ADDRESS = "address";
private static final String FIELD_GROUP_ID = "group_id";
private static final String FIELD_SERVER_UUID = "server_uuid";
private static final String FIELD_WEIGHT = "weight";
private static final String FIELD_SCHEMA_NAME = "schema_name";
private static final String FIELD_TABLE_NAME = "table_name";
private static final String FIELD_COLUMN_NAME = "column_name";
private static final String FIELD_LOWER_BOUND = "lower_bound";
private static final String FIELD_SHARD_ID = "shard_id";
private static final String FIELD_MAPPING_ID = "mapping_id";
private static final String FIELD_GLOBAL_GROUP_ID = "global_group_id";
private static final String FIELD_TYPE_NAME = "type_name";
private static final String FIELD_RESULT = "result";
private XmlRpcMethodCaller methodCaller;
public XmlRpcClient(String url, String username, String password) throws FabricCommunicationException {
this.methodCaller = new InternalXmlRpcMethodCaller(url);
if (username != null && !"".equals(username) && password != null) {
this.methodCaller = new AuthenticatedXmlRpcMethodCaller(this.methodCaller, url, username, password);
}
}
/**
* Unmarshall a response representing a server.
*/
private static Server unmarshallServer(Map serverData) throws FabricCommunicationException {
ServerMode mode;
ServerRole role;
String host;
int port;
try {
// dump.servers returns integer mode/status
if (Integer.class.equals(serverData.get(FIELD_MODE).getClass())) {
mode = ServerMode.getFromConstant((Integer) serverData.get(FIELD_MODE));
role = ServerRole.getFromConstant((Integer) serverData.get(FIELD_STATUS));
host = (String) serverData.get(FIELD_HOST);
port = (Integer) serverData.get(FIELD_PORT);
} else {
// sharding.lookup_servers returns a different format
mode = ServerMode.valueOf((String) serverData.get(FIELD_MODE));
role = ServerRole.valueOf((String) serverData.get(FIELD_STATUS));
String hostnameAndPort[] = ((String) serverData.get(FIELD_ADDRESS)).split(":");
host = hostnameAndPort[0];
port = Integer.valueOf(hostnameAndPort[1]);
}
Server s = new Server((String) serverData.get(FIELD_GROUP_ID), (String) serverData.get(FIELD_SERVER_UUID), host, port, mode, role,
(Double) serverData.get(FIELD_WEIGHT));
return s;
} catch (Exception ex) {
throw new FabricCommunicationException("Unable to parse server definition", ex);
}
}
/**
* Convert a list of string/string/bool to Server objects.
*/
private static Set toServerSet(List