List of usage examples for org.apache.commons.configuration ConversionException ConversionException
public ConversionException(Throwable cause)
ConversionException
with specified nested Throwable
. From source file:edu.usc.goffish.gofs.tools.GoFSFormat.java
public static void main(String[] args) throws IOException { if (args.length < REQUIRED_ARGS) { PrintUsageAndQuit(null);//from w w w. j ava 2 s.c om } if (args.length == 1 && args[0].equals("-help")) { PrintUsageAndQuit(null); } Path executableDirectory; try { executableDirectory = Paths .get(GoFSFormat.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent(); } catch (URISyntaxException e) { throw new RuntimeException("Unexpected error retrieving executable location", e); } Path configPath = executableDirectory.resolve(DEFAULT_CONFIG).normalize(); boolean copyBinaries = false; // parse optional arguments int i = 0; OptArgLoop: for (i = 0; i < args.length - REQUIRED_ARGS; i++) { switch (args[i]) { case "-config": i++; try { configPath = Paths.get(args[i]); } catch (InvalidPathException e) { PrintUsageAndQuit("Config file - " + e.getMessage()); } break; case "-copyBinaries": copyBinaries = true; break; default: break OptArgLoop; } } if (args.length - i < REQUIRED_ARGS) { PrintUsageAndQuit(null); } // finished parsing args if (i < args.length) { PrintUsageAndQuit("Unrecognized argument \"" + args[i] + "\""); } // parse config System.out.println("Parsing config..."); PropertiesConfiguration config = new PropertiesConfiguration(); config.setDelimiterParsingDisabled(true); try { config.load(Files.newInputStream(configPath)); } catch (ConfigurationException e) { throw new IOException(e); } // retrieve data nodes ArrayList<URI> dataNodes; { String[] dataNodesArray = config.getStringArray(GOFS_DATANODES_KEY); if (dataNodesArray.length == 0) { throw new ConversionException("Config must contain key " + GOFS_DATANODES_KEY); } dataNodes = new ArrayList<>(dataNodesArray.length); if (dataNodesArray.length == 0) { throw new ConversionException("Config key " + GOFS_DATANODES_KEY + " has invalid format - must define at least one data node"); } try { for (String node : dataNodesArray) { URI dataNodeURI = new URI(node); if (!"file".equalsIgnoreCase(dataNodeURI.getScheme())) { throw new ConversionException("config key " + GOFS_DATANODES_KEY + " value \"" + dataNodeURI + "\" has invalid format - data node urls must have 'file' scheme"); } else if (dataNodeURI.getPath() == null || dataNodeURI.getPath().isEmpty()) { throw new ConversionException("config key " + GOFS_DATANODES_KEY + " value \"" + dataNodeURI + "\" has invalid format - data node urls must have an absolute path specified"); } // ensure uri ends with a slash, so we know it is a directory if (!dataNodeURI.getPath().endsWith("/")) { dataNodeURI = dataNodeURI.resolve(dataNodeURI.getPath() + "/"); } dataNodes.add(dataNodeURI); } } catch (URISyntaxException e) { throw new ConversionException( "Config key " + GOFS_DATANODES_KEY + " has invalid format - " + e.getMessage()); } } // validate serializer type Class<? extends ISliceSerializer> serializerType; { String serializerTypeName = config.getString(GOFS_SERIALIZER_KEY); if (serializerTypeName == null) { throw new ConversionException("Config must contain key " + GOFS_SERIALIZER_KEY); } try { serializerType = SliceSerializerProvider.loadSliceSerializerType(serializerTypeName); } catch (ReflectiveOperationException e) { throw new ConversionException( "Config key " + GOFS_SERIALIZER_KEY + " has invalid format - " + e.getMessage()); } } // retrieve name node IInternalNameNode nameNode; try { nameNode = NameNodeProvider.loadNameNodeFromConfig(config, GOFS_NAMENODE_TYPE_KEY, GOFS_NAMENODE_LOCATION_KEY); } catch (ReflectiveOperationException e) { throw new RuntimeException("Unable to load name node", e); } System.out.println("Contacting name node..."); // validate name node if (!nameNode.isAvailable()) { throw new IOException("Name node at " + nameNode.getURI() + " is not available"); } System.out.println("Contacting data nodes..."); // validate data nodes for (URI dataNode : dataNodes) { // only attempt ssh if host exists if (dataNode.getHost() != null) { try { SSHHelper.SSH(dataNode, "true"); } catch (IOException e) { throw new IOException("Data node at " + dataNode + " is not available", e); } } } // create temporary directory Path workingDir = Files.createTempDirectory("gofs_format"); try { // create deploy directory Path deployDirectory = Files.createDirectory(workingDir.resolve(DATANODE_DIR_NAME)); // create empty slice directory Files.createDirectory(deployDirectory.resolve(DataNode.DATANODE_SLICE_DIR)); // copy binaries if (copyBinaries) { System.out.println("Copying binaries..."); FileUtils.copyDirectory(executableDirectory.toFile(), deployDirectory.resolve(executableDirectory.getFileName()).toFile()); } // write config file Path dataNodeConfigFile = deployDirectory.resolve(DataNode.DATANODE_CONFIG); try { // create config for every data node and scp deploy folder into place for (URI dataNodeParent : dataNodes) { URI dataNode = dataNodeParent.resolve(DATANODE_DIR_NAME); PropertiesConfiguration datanode_config = new PropertiesConfiguration(); datanode_config.setDelimiterParsingDisabled(true); datanode_config.setProperty(DataNode.DATANODE_INSTALLED_KEY, true); datanode_config.setProperty(DataNode.DATANODE_NAMENODE_TYPE_KEY, config.getString(GOFS_NAMENODE_TYPE_KEY)); datanode_config.setProperty(DataNode.DATANODE_NAMENODE_LOCATION_KEY, config.getString(GOFS_NAMENODE_LOCATION_KEY)); datanode_config.setProperty(DataNode.DATANODE_LOCALHOSTURI_KEY, dataNode.toString()); try { datanode_config.save(Files.newOutputStream(dataNodeConfigFile)); } catch (ConfigurationException e) { throw new IOException(e); } System.out.println("Formatting data node " + dataNode.toString() + "..."); // scp everything into place on the data node SCPHelper.SCP(deployDirectory, dataNodeParent); // update name node nameNode.addDataNode(dataNode); } // update name node nameNode.setSerializer(serializerType); } catch (Exception e) { System.out.println( "ERROR: data node formatting interrupted - name node and data nodes are in an inconsistent state and require clean up"); throw e; } System.out.println("GoFS format complete"); } finally { FileUtils.deleteQuietly(workingDir.toFile()); } }
From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java
public static IInternalNameNode loadNameNodeFromConfig(Configuration config, String nameNodeTypeKey, String nameNodeLocationKey) throws ClassNotFoundException, ReflectiveOperationException { // retrieve name node type Class<? extends IInternalNameNode> nameNodeType; {/* w w w . ja v a2 s .c o m*/ String nameNodeTypeString = config.getString(nameNodeTypeKey); if (nameNodeTypeString == null) { throw new ConversionException("Config must contain key " + nameNodeTypeKey); } try { nameNodeType = NameNodeProvider.loadNameNodeType(nameNodeTypeString); } catch (ReflectiveOperationException e) { throw new ConversionException( "Config key " + nameNodeTypeKey + " has invalid format - " + e.getMessage()); } } // retrieve name node location URI nameNodeLocation; { String nameNodeLocationString = config.getString(nameNodeLocationKey); if (nameNodeLocationString == null) { throw new ConversionException("Config must contain key " + nameNodeLocationKey); } try { nameNodeLocation = new URI(nameNodeLocationString); } catch (URISyntaxException e) { throw new ConversionException( "Config key " + nameNodeLocationKey + " has invalid format - " + e.getMessage()); } } return loadNameNode(nameNodeType, nameNodeLocation); }
From source file:net.erdfelt.android.sdkfido.configer.EnumConverter.java
@SuppressWarnings("rawtypes") public Object convert(Class type, Object value) { if (type.isEnum()) { String key = String.valueOf(value).toUpperCase(); return values.get(key); } else {/*from w w w. ja va 2s . co m*/ throw new ConversionException("Not an Enum class"); } }
From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationEnumValueExtractor.java
@Override public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { String value = configuration.getString(prefix + key); if (value != null && !value.trim().equals("")) { Object enums[] = field.getType().getEnumConstants(); for (int i = 0; i < enums.length; i++) { if (((Enum<?>) enums[i]).name().equals(value)) { return enums[i]; }/*from ww w . ja v a 2 s .co m*/ } } else { return null; } throw new ConversionException(getBundle().getString("configuration-not-conversion", value, field.getDeclaringClass().getCanonicalName())); }
From source file:cz.cas.lib.proarc.common.imports.ImportProfile.java
private Integer getPositiveInteger(String key) { Integer val = config.getInteger(key, null); if (val != null && val <= 0) { throw new ConversionException(key + " expects positive integer!"); }/* ww w. j ava 2 s .c o m*/ return val; }