use of org.locationtech.geowave.core.store.server.ServerOpConfig.ServerOpScope in project geowave by locationtech.
the class ServerOpHelper method updateServerOps.
public static boolean updateServerOps(final ServerSideOperations operations, final String index, final ServerOpConfig... configs) {
if ((configs != null) && (configs.length > 0)) {
final Map<String, ImmutableSet<ServerOpScope>> iteratorScopes = operations.listServerOps(index);
for (final ServerOpConfig config : configs) {
boolean mustDelete = false;
boolean exists = false;
final ImmutableSet<ServerOpScope> existingScopes = iteratorScopes.get(config.getServerOpName());
ImmutableSet<ServerOpScope> configuredScopes;
if (config.getScopes() == null) {
configuredScopes = Sets.immutableEnumSet(EnumSet.allOf(ServerOpScope.class));
} else {
configuredScopes = Sets.immutableEnumSet(config.getScopes());
}
Map<String, String> configuredOptions = null;
if (existingScopes != null) {
if (existingScopes.size() == configuredScopes.size()) {
exists = true;
for (final ServerOpScope s : existingScopes) {
if (!configuredScopes.contains(s)) {
// this iterator exists with the wrong
// scope, we will assume we want to remove
// it and add the new configuration
LOGGER.warn("found iterator '" + config.getServerOpName() + "' missing scope '" + s.name() + "', removing it and re-attaching");
mustDelete = true;
break;
}
}
}
if (existingScopes.size() > 0) {
// see if the options are the same, if they are not
// the same, apply a merge with the existing options
// and the configured options
final Iterator<ServerOpScope> it = existingScopes.iterator();
while (it.hasNext()) {
final ServerOpScope scope = it.next();
final Map<String, String> existingOptions = operations.getServerOpOptions(index, config.getServerOpName(), scope);
configuredOptions = config.getOptions(existingOptions);
if (existingOptions == null) {
mustDelete = (configuredOptions == null);
} else if (configuredOptions == null) {
mustDelete = true;
} else {
// neither are null, compare the size of
// the entry sets and check that they
// are equivalent
final Set<Entry<String, String>> existingEntries = existingOptions.entrySet();
final Set<Entry<String, String>> configuredEntries = configuredOptions.entrySet();
if (existingEntries.size() != configuredEntries.size()) {
mustDelete = true;
} else {
mustDelete = (!existingEntries.containsAll(configuredEntries));
}
}
// for each scope
break;
}
}
}
if (configuredOptions == null) {
configuredOptions = config.getOptions(new HashMap<String, String>());
}
if (mustDelete) {
operations.updateServerOp(index, config.getServerOpPriority(), config.getServerOpName(), config.getServerOpClass(), configuredOptions, existingScopes, configuredScopes);
} else if (!exists) {
operations.addServerOp(index, config.getServerOpPriority(), config.getServerOpName(), config.getServerOpClass(), configuredOptions, configuredScopes);
}
}
}
return true;
}
use of org.locationtech.geowave.core.store.server.ServerOpConfig.ServerOpScope in project geowave by locationtech.
the class ServerSideOperationsObserver method start.
@Override
public void start(final CoprocessorEnvironment env) throws IOException {
opStore = new ServerSideOperationStore();
final Configuration config = env.getConfiguration();
final Map<String, List<String>> uniqueOpsWithOptionKeys = new HashMap<>();
for (final Map.Entry<String, String> entry : config) {
if (entry.getKey().startsWith(ServerSideOperationUtils.SERVER_OP_PREFIX)) {
final String key = entry.getKey();
final int index = StringUtils.ordinalIndexOf(key, ".", 4);
if (index > 0) {
final String uniqueOp = key.substring(0, index + 1);
List<String> optionKeys = uniqueOpsWithOptionKeys.get(uniqueOp);
if (optionKeys == null) {
optionKeys = new ArrayList<>();
uniqueOpsWithOptionKeys.put(uniqueOp, optionKeys);
}
if (key.length() > (uniqueOp.length() + 1 + SERVER_OP_OPTIONS_PREFIX_LENGTH)) {
if (key.substring(uniqueOp.length(), uniqueOp.length() + SERVER_OP_OPTIONS_PREFIX_LENGTH).equals(ServerSideOperationUtils.SERVER_OP_OPTIONS_PREFIX)) {
optionKeys.add(key.substring(uniqueOp.length() + 1 + SERVER_OP_OPTIONS_PREFIX_LENGTH));
}
}
}
}
}
for (final Entry<String, List<String>> uniqueOpAndOptions : uniqueOpsWithOptionKeys.entrySet()) {
final String uniqueOp = uniqueOpAndOptions.getKey();
final String priorityStr = config.get(uniqueOp + ServerSideOperationUtils.SERVER_OP_PRIORITY_KEY);
if ((priorityStr == null) || priorityStr.isEmpty()) {
LOGGER.warn("Skipping server op - unable to find priority for '" + uniqueOp + "'");
continue;
}
final int priority = Integer.parseInt(priorityStr);
final String commaDelimitedScopes = config.get(uniqueOp + ServerSideOperationUtils.SERVER_OP_SCOPES_KEY);
if ((commaDelimitedScopes == null) || commaDelimitedScopes.isEmpty()) {
LOGGER.warn("Skipping server op - unable to find scopes for '" + uniqueOp + "'");
continue;
}
final ImmutableSet<ServerOpScope> scopes = HBaseUtils.stringToScopes(commaDelimitedScopes);
final String classIdStr = config.get(uniqueOp + ServerSideOperationUtils.SERVER_OP_CLASS_KEY);
if ((classIdStr == null) || classIdStr.isEmpty()) {
LOGGER.warn("Skipping server op - unable to find class ID for '" + uniqueOp + "'");
continue;
}
final List<String> optionKeys = uniqueOpAndOptions.getValue();
final Map<String, String> optionsMap = new HashMap<>();
for (final String optionKey : optionKeys) {
final String optionValue = config.get(uniqueOp + ServerSideOperationUtils.SERVER_OP_OPTIONS_PREFIX + "." + optionKey);
optionsMap.put(optionKey, optionValue);
}
final String[] uniqueOpSplit = uniqueOp.split("\\.");
opStore.addOperation(HBaseUtils.readConfigSafeTableName(uniqueOpSplit[1]), HBaseUtils.readConfigSafeTableName(uniqueOpSplit[2]), uniqueOpSplit[3], priority, scopes, ByteArrayUtils.byteArrayFromString(classIdStr), optionsMap);
}
RegionCoprocessor.super.start(env);
}
use of org.locationtech.geowave.core.store.server.ServerOpConfig.ServerOpScope in project geowave by locationtech.
the class HBaseOperations method addConfig.
private static void addConfig(final TableDescriptorBuilder bldr, final String namespace, final String qualifier, final int priority, final String serverOpName, final String operationClassName, final ImmutableSet<ServerOpScope> scopes, final Map<String, String> properties) {
final String basePrefix = new StringBuilder(ServerSideOperationUtils.SERVER_OP_PREFIX).append(".").append(HBaseUtils.writeTableNameAsConfigSafe(namespace)).append(".").append(HBaseUtils.writeTableNameAsConfigSafe(qualifier)).append(".").append(serverOpName).append(".").toString();
bldr.setValue(basePrefix + ServerSideOperationUtils.SERVER_OP_CLASS_KEY, ByteArrayUtils.byteArrayToString(URLClassloaderUtils.toClassId(operationClassName)));
bldr.setValue(basePrefix + ServerSideOperationUtils.SERVER_OP_PRIORITY_KEY, Integer.toString(priority));
bldr.setValue(basePrefix + ServerSideOperationUtils.SERVER_OP_SCOPES_KEY, scopes.stream().map(ServerOpScope::name).collect(Collectors.joining(",")));
final String optionsPrefix = String.format(basePrefix + ServerSideOperationUtils.SERVER_OP_OPTIONS_PREFIX + ".");
for (final Entry<String, String> e : properties.entrySet()) {
bldr.setValue(optionsPrefix + e.getKey(), e.getValue());
}
}
Aggregations