use of voldemort.VoldemortException in project voldemort by voldemort.
the class JmxUtils method extractAttributeInfo.
/**
* Extract all operations from the given object that have been annotated
* with the Jmx annotation. Operations are all methods that are marked with
* the JMX annotation and are not getters and setters (which are extracted
* as attributes).
*
* @param object The object to process
* @return An array of attributes taken from the object
*/
public static ModelMBeanAttributeInfo[] extractAttributeInfo(Object object) {
Map<String, Method> getters = new HashMap<String, Method>();
Map<String, Method> setters = new HashMap<String, Method>();
Map<String, String> descriptions = new HashMap<String, String>();
for (Method m : object.getClass().getMethods()) {
JmxGetter getter = m.getAnnotation(JmxGetter.class);
if (getter != null) {
getters.put(getter.name(), m);
descriptions.put(getter.name(), getter.description());
}
JmxSetter setter = m.getAnnotation(JmxSetter.class);
if (setter != null) {
setters.put(setter.name(), m);
descriptions.put(setter.name(), setter.description());
}
}
Set<String> attributes = new HashSet<String>(getters.keySet());
attributes.addAll(setters.keySet());
List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();
for (String name : attributes) {
try {
Method getter = getters.get(name);
Method setter = setters.get(name);
ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(name, descriptions.get(name), getter, setter);
Descriptor descriptor = info.getDescriptor();
if (getter != null)
descriptor.setField("getMethod", getter.getName());
if (setter != null)
descriptor.setField("setMethod", setter.getName());
info.setDescriptor(descriptor);
infos.add(info);
} catch (IntrospectionException e) {
throw new VoldemortException(e);
}
}
return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminCommandStream method readEntriesBinary.
private static Iterator<Pair<ByteArray, Versioned<byte[]>>> readEntriesBinary(File inputDir, String storeName) throws IOException {
File inputFile = new File(inputDir, storeName + ".entries");
if (!inputFile.exists()) {
throw new FileNotFoundException("File " + inputFile.getAbsolutePath() + " does not exist!");
}
final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
return new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {
@Override
protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
try {
int length = dis.readInt();
byte[] keyBytes = new byte[length];
ByteUtils.read(dis, keyBytes);
length = dis.readInt();
byte[] versionBytes = new byte[length];
ByteUtils.read(dis, versionBytes);
length = dis.readInt();
byte[] valueBytes = new byte[length];
ByteUtils.read(dis, valueBytes);
ByteArray key = new ByteArray(keyBytes);
VectorClock version = new VectorClock(versionBytes);
Versioned<byte[]> value = new Versioned<byte[]>(valueBytes, version);
return new Pair<ByteArray, Versioned<byte[]>>(key, value);
} catch (EOFException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
return endOfData();
} catch (IOException e) {
try {
dis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
throw new VoldemortException("Error reading from input file ", e);
}
}
};
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AbstractConsistencyFixer method doReads.
/**
*
* @param nodeIdList
* @param keyInBytes
* @param keyInHexFormat
* @return
*/
private Map<Integer, QueryKeyResult> doReads(final List<Integer> nodeIdList, final byte[] keyInBytes, final String keyInHexFormat) {
Map<Integer, QueryKeyResult> nodeIdToKeyValues = new HashMap<Integer, QueryKeyResult>();
ByteArray key = new ByteArray(keyInBytes);
for (int nodeId : nodeIdList) {
List<Versioned<byte[]>> values = null;
try {
values = this.adminClient.storeOps.getNodeKey(this.storeInstance.getStoreDefinition().getName(), nodeId, key);
nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, values));
} catch (VoldemortException ve) {
nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, ve));
}
}
return nodeIdToKeyValues;
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class RebalanceUtils method dropZone.
/**
* Similar to {@link RebalanceUtils#vacateZone(Cluster, int)}, takes the
* current store definitions in the cluster and creates store definitions
* with the specified zone effectively dropped.
*
* In order to drop a zone, we adjust the total replication factor and
* remove zone replication factor for the dropped zone
*
*
* @param currentStoreDefs
* @param dropZoneId
* @return the adjusted list of store definitions
*/
public static List<StoreDefinition> dropZone(List<StoreDefinition> currentStoreDefs, int dropZoneId) {
List<StoreDefinition> adjustedStoreDefList = new ArrayList<StoreDefinition>();
for (StoreDefinition storeDef : currentStoreDefs) {
HashMap<Integer, Integer> zoneRepFactorMap = storeDef.getZoneReplicationFactor();
if (!zoneRepFactorMap.containsKey(dropZoneId)) {
throw new VoldemortException("Store " + storeDef.getName() + " does not have replication factor for zone " + dropZoneId);
}
StoreDefinitionBuilder adjustedStoreDefBuilder = StoreDefinitionUtils.getBuilderForStoreDef(storeDef);
if (!storeDef.hasPreferredReads()) {
adjustedStoreDefBuilder.setPreferredReads(null);
}
if (!storeDef.hasPreferredWrites()) {
adjustedStoreDefBuilder.setPreferredWrites(null);
}
// Copy all zone replication factor entries except for dropped zone
HashMap<Integer, Integer> adjustedZoneRepFactorMap = new HashMap<Integer, Integer>();
for (Integer zoneId : zoneRepFactorMap.keySet()) {
if (zoneId != dropZoneId) {
adjustedZoneRepFactorMap.put(zoneId, zoneRepFactorMap.get(zoneId));
}
}
adjustedStoreDefBuilder.setZoneReplicationFactor(adjustedZoneRepFactorMap);
// adjust the replication factor
int zoneRepFactor = zoneRepFactorMap.get(dropZoneId);
adjustedStoreDefBuilder.setReplicationFactor(adjustedStoreDefBuilder.getReplicationFactor() - zoneRepFactor);
adjustedStoreDefList.add(adjustedStoreDefBuilder.build());
}
return adjustedStoreDefList;
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class RebalanceUtils method validateClusterZonesSame.
/**
* Confirms that both clusters have the same set of zones defined.
*
* @param lhs
* @param rhs
*/
public static void validateClusterZonesSame(final Cluster lhs, final Cluster rhs) {
Set<Zone> lhsSet = new HashSet<Zone>(lhs.getZones());
Set<Zone> rhsSet = new HashSet<Zone>(rhs.getZones());
if (!lhsSet.equals(rhsSet))
throw new VoldemortException("Zones are not the same [ lhs cluster zones (" + lhs.getZones() + ") not equal to rhs cluster zones (" + rhs.getZones() + ") ]");
}
Aggregations