summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephan Schwär2020-10-08 03:20:44 +0200
committerStephan Schwär2020-10-08 03:20:44 +0200
commite69b3a703d992e6a6623fd8578106cdb4224871d (patch)
tree8dbf41d976f49d22f263304b85c905e77c1050e7 /src
parentAdd meta and config files for ovf format (diff)
downloadmaster-sync-shared-e69b3a703d992e6a6623fd8578106cdb4224871d.tar.gz
master-sync-shared-e69b3a703d992e6a6623fd8578106cdb4224871d.tar.xz
master-sync-shared-e69b3a703d992e6a6623fd8578106cdb4224871d.zip
Improve comments describing new classes and cleanup
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/util/vm/OvfConfig.java85
-rw-r--r--src/main/java/org/openslx/util/vm/OvfMetaData.java38
2 files changed, 50 insertions, 73 deletions
diff --git a/src/main/java/org/openslx/util/vm/OvfConfig.java b/src/main/java/org/openslx/util/vm/OvfConfig.java
index 3055075..df8b0ca 100644
--- a/src/main/java/org/openslx/util/vm/OvfConfig.java
+++ b/src/main/java/org/openslx/util/vm/OvfConfig.java
@@ -20,86 +20,61 @@ import org.openslx.util.vm.VmMetaData.HardDisk;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
-
/**
* Class handling the parsing of a .ovf machine description file
- * For now, only used to parse the xml to get the path of the vmdk
- * from the ovf for sanity checking and cleanup after conversion.
+ * For now only a dummy for conversion and will be replaced in
+ * the image upload flow after converting the ovf to vmx.
*/
-public class OvfConfig
-{
- private static final Logger LOGGER = Logger.getLogger( OvfConfig.class );
-
- // key information set during initial parsing of the XML file
+public class OvfConfig {
+ private static final Logger LOGGER = Logger.getLogger(OvfConfig.class);
+
+ // key information set during initial parsing of the XML file
private String osName = new String();
private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>();
// XPath and DOM parsing related members
- private Document doc = null;
-
+ private Document doc = null;
- public OvfConfig( File file ) throws IOException, UnsupportedVirtualizerFormatException
- {
+ public OvfConfig(File file) throws IOException, UnsupportedVirtualizerFormatException {
LOGGER.info("Entering OvfConfig class creation");
- // first validate xml
- // try {
- // SchemaFactory factory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
- // InputStream xsdStream = OvfConfig.class.getResourceAsStream( "/master-sync-shared/xml/ovf_1.1.1.xsd" );
- // LOGGER.info("xsdStream creation worked");
- // if ( xsdStream == null ) {
- // LOGGER.warn( "Cannot validate ovf XML: No XSD found in JAR" );
- // } else {
- // LOGGER.info("Before schema creation");
- // Schema schema = factory.newSchema( new StreamSource( xsdStream ) );
- // LOGGER.info("Created schema class");
- // Validator validator = schema.newValidator();
- // LOGGER.info("Created validator class");
- // validator.validate( new StreamSource( file ) );
- // LOGGER.info("Validated");
- // }
- // } catch ( SAXException e ) {
- // LOGGER.error( "Selected ovf file was not validated against the XSD schema: " + e.getMessage() );
- // }
- LOGGER.info("XSD validation worked.");
- // valid xml, try to create the DOM
- doc = XmlHelper.parseDocumentFromStream( new FileInputStream( file ) );
- doc = XmlHelper.removeFormattingNodes( doc );
- if ( doc == null )
- throw new UnsupportedVirtualizerFormatException( "Could not create DOM from given ovf machine configuration file!" );
+ doc = XmlHelper.parseDocumentFromStream(new FileInputStream(file));
+ doc = XmlHelper.removeFormattingNodes(doc);
+ if (doc == null)
+ throw new UnsupportedVirtualizerFormatException(
+ "Could not create DOM from given ovf machine configuration file!");
LOGGER.info("DOM creation worked");
init();
- }
-
- /**
- * Main initialization functions parsing the document created during the constructor.
- * @throws UnsupportedVirtualizerFormatException
+ }
+
+ /**
+ * Main initialization functions parsing the document created during the
+ * constructor.
+ *
+ * @throws UnsupportedVirtualizerFormatException
*/
- private void init() throws UnsupportedVirtualizerFormatException
- {
+ private void init() throws UnsupportedVirtualizerFormatException {
LOGGER.info("Entering OvfConfig init");
- if ( Util.isEmptyString( getDisplayName() ) ) {
- throw new UnsupportedVirtualizerFormatException( "Machine doesn't have a name" );
+ if (Util.isEmptyString(getDisplayName())) {
+ throw new UnsupportedVirtualizerFormatException("Machine doesn't have a name");
}
- LOGGER.info( getDisplayName() );
+ LOGGER.info(getDisplayName());
// try {
-
// setHdds();
// } catch ( XPathExpressionException e ) {
// LOGGER.debug( "Could not initialize VBoxConfig", e );
// return;
// }
- }
-
- /**
+ }
+
+ /**
* Getter for the display name
*
* @return the display name of this VM
*/
- public String getDisplayName()
- {
+ public String getDisplayName() {
try {
- return XmlHelper.XPath.compile( "/Envelope/VirtualSystem/Name" ).evaluate( this.doc );
- } catch ( XPathExpressionException e ) {
+ return XmlHelper.XPath.compile("/Envelope/VirtualSystem/Name").evaluate(this.doc);
+ } catch (XPathExpressionException e) {
return "";
}
}
diff --git a/src/main/java/org/openslx/util/vm/OvfMetaData.java b/src/main/java/org/openslx/util/vm/OvfMetaData.java
index f5a45bf..fae8b52 100644
--- a/src/main/java/org/openslx/util/vm/OvfMetaData.java
+++ b/src/main/java/org/openslx/util/vm/OvfMetaData.java
@@ -20,33 +20,35 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-
+/**
+ * Class handling the metadata of ovf images. Only needed
+ * until the ovf has been converted into a vmx.
+ */
public class OvfMetaData extends VmMetaData {
- private static final Logger LOGGER = Logger.getLogger( OvfMetaData.class );
+ private static final Logger LOGGER = Logger.getLogger(OvfMetaData.class);
private final OvfConfig config;
- public OvfMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException
- {
- super( osList );
+ public OvfMetaData(List<OperatingSystem> osList, File file)
+ throws IOException, UnsupportedVirtualizerFormatException {
+ super(osList);
LOGGER.info("Constructor worked");
- this.config = new OvfConfig( file );
+ this.config = new OvfConfig(file);
LOGGER.info("Creating config worked");
init();
LOGGER.info("Init worked");
}
-
- private void init()
- {
- registerVirtualHW();
- displayName = config.getDisplayName();
- // setOs( config.getOsName() );
- // this.isMachineSnapshot = config.isMachineSnapshot();
- // for ( HardDisk hardDisk : config.getHdds() ) {
- // hdds.add( hardDisk );
- // }
- }
+
+ private void init() {
+ registerVirtualHW();
+ displayName = config.getDisplayName();
+ // setOs( config.getOsName() );
+ // this.isMachineSnapshot = config.isMachineSnapshot();
+ // for ( HardDisk hardDisk : config.getHdds() ) {
+ // hdds.add( hardDisk );
+ // }
+ }
@Override
public byte[] getFilteredDefinitionArray() {
@@ -203,5 +205,5 @@ public class OvfMetaData extends VmMetaData {
// TODO Auto-generated method stub
}
-
+
}