From 1f58a5c478c82978418cb152ad43a7cc18a002a8 Mon Sep 17 00:00:00 2001 From: Victor Mocanu Date: Thu, 2 Nov 2017 17:12:56 +0100 Subject: [VBox] new working coppy added new Javadocs, updated getters of VBoxMetaData still got TODOs --- src/main/java/org/openslx/util/vm/VboxConfig.java | 48 ++++++---- .../java/org/openslx/util/vm/VboxMetaData.java | 104 +++++++++++++++------ src/main/java/org/openslx/util/vm/VmMetaData.java | 35 ++++++- .../java/org/openslx/util/vm/VmwareConfig.java | 2 - 4 files changed, 137 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java index ee9cd25..6a44402 100644 --- a/src/main/java/org/openslx/util/vm/VboxConfig.java +++ b/src/main/java/org/openslx/util/vm/VboxConfig.java @@ -41,13 +41,13 @@ public class VboxConfig private Document doc = null; private String displayNameExpression = "/VirtualBox/Machine/@name"; - private String displayName; + private String displayName = new String(); private String osTypeExpression = "/VirtualBox/Machine/@OSType"; - private String osName = new String();; + private String osName = new String(); private String hddsExpression = "/VirtualBox/Machine/MediaRegistry/HardDisks/*"; - private ArrayList hddsArray = new ArrayList();; + private ArrayList hddsArray = new ArrayList(); // a black list of sorts of tags that need to be removed from the .vbox file private static String[] blackList = { "ExtraData", "Adapter", "GuestProperties", "LPT", "StorageController", "FloppyImages", "DVDImages", "AttachedDevice" }; @@ -77,7 +77,6 @@ public class VboxConfig LOGGER.warn( "Could not parse .Vbox", e ); throw new UnsupportedVirtualizerFormatException( "Could not create VBoxConfig!" ); } - displayName = new String(); } /** @@ -119,6 +118,8 @@ public class VboxConfig /** * initialization function + * reads the doc, sets Machine name, os type, sets the hdds, adds placeholders, removes unwanted/ + * unneeded nodes */ public void init() { @@ -150,13 +151,18 @@ public class VboxConfig NodeList hdds = findANode( "HardDisk" ); for ( int i = 0; i < hdds.getLength(); i++ ) { Element hdd = (Element)hdds.item( i ); - if ( hdd.getAttribute( "location" ).equals( "#some_fancy_HDD_place_holder" ) ) { + if ( hdd.getAttribute( "location" ).equals( "#OpenSLX_HDD_place_holder" ) ) { return true; } } return false; } + /** + * Function finds and saves the name of the machine + * + * @throws XPathExpressionException + */ public void setMachineName() throws XPathExpressionException { String name = xPath.compile( displayNameExpression ).evaluate( this.doc ); @@ -165,6 +171,11 @@ public class VboxConfig } } + /** + * Function finds and saves the name of the os + * + * @throws XPathExpressionException + */ public void setOsType() throws XPathExpressionException { String os = xPath.compile( osTypeExpression ).evaluate( this.doc ); @@ -179,8 +190,6 @@ public class VboxConfig Object result = hddsExpr.evaluate( this.doc, XPathConstants.NODESET ); // take all the hdd nodes NodeList nodes = (NodeList)result; - - // TODO find all HardDisk under HardDisks, give them to the hdds // foreach hdd in the hddnodes do: for ( int i = 0; i < nodes.getLength(); i++ ) { // have the node @@ -191,24 +200,19 @@ public class VboxConfig String fileName = hddElement.getAttribute( "location" ); // take the uuid String uuid = hddElement.getAttribute( "uuid" ); - - // do the loop the loop // search in the xml object and give back the parent of the parent of the node that is called Image and has the given uuid String pathToParent = givePathToStorageController( uuid ); XPathExpression attachedDevicesExpr = xPath.compile( pathToParent ); Object devicesResult = attachedDevicesExpr.evaluate( this.doc, XPathConstants.NODESET ); NodeList devicesNodes = (NodeList)devicesResult; - // TODO -- ehm...should only have 1 element...what do when there are more? if ( devicesNodes.getLength() > 1 ) { LOGGER.error( "There can not be more HDDs with the same UUID!" ); return; } - Element deviceElement = (Element)devicesNodes.item( 0 ); String controllerDevice = deviceElement.getAttribute( "type" ); String bus = deviceElement.getAttribute( "name" ); - DriveBusType busType = null; if ( bus.equals( "IDE" ) ) { busType = DriveBusType.IDE; @@ -225,13 +229,13 @@ public class VboxConfig public void addPlaceHolders() { // placeholder for the location of the virtual hdd - changeAttribute( "HardDisk", "location", "#some_fancy_HDD_place_holder" ); + changeAttribute( "HardDisk", "location", "#OpenSLX_HDD_place_holder" ); // placeholder for the memory - changeAttribute( "Memory", "RAMSize", "#some_fancy_MEMORY_place_holder" ); + changeAttribute( "Memory", "RAMSize", "#OpenSLX_MEMORY_place_holder" ); // placeholder for the CPU - changeAttribute( "CPU", "count", "#some_fancy_CPU_place_holder" ); + changeAttribute( "CPU", "count", "#OpenSLX_CPU_place_holder" ); // add placeholder for the uuid of the virtual harddrive. // must be added on 2 positions...in the HardDisk tag and the attachedDevice tag @@ -240,13 +244,13 @@ public class VboxConfig for ( int i = 0; i < hdds.getLength(); i++ ) { Element hdd = (Element)findANode( "HardDisk" ).item( i ); String uuid = hdd.getAttribute( "uuid" ); - hdd.setAttribute( "uuid", "#some_fancy_HDDUUID_" + i + "_placeholder" ); + hdd.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" ); NodeList images = findANode( "Image" ); Element image; for ( int j = 0; j < images.getLength(); j++ ) { if ( ( (Element)images.item( j ) ).getAttribute( "uuid" ).equals( uuid ) ) { image = (Element)images.item( j ); - image.setAttribute( "uuid", "#some_fancy_HDDUUID_" + i + "_placeholder" ); + image.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" ); break; } } @@ -405,7 +409,6 @@ public class VboxConfig XPathExpression blackedExpr = xPath.compile( blackedExpression ); NodeList blackedNodes = (NodeList)blackedExpr.evaluate( this.doc, XPathConstants.NODESET ); - //LOGGER.debug( blackedNodes.getLength() ); for ( int i = 0; i < blackedNodes.getLength(); i++ ) { // get the child node Element child = (Element)blackedNodes.item( i ); @@ -413,9 +416,14 @@ public class VboxConfig if ( child.getTagName().equals( "Adapter" ) && child.getAttribute( "enabled" ).equals( "true" ) ) { // we need to remove the children of the active network adapter // these are the mode of network connection and disabled modes...they go together -> see wiki - if ( child.getChildNodes().item( 0 ).getNodeName().equals( "#text" ) && !child.getChildNodes().item( 1 ).getNodeName().equals( "#text" ) ) { - removeNode( child.getChildNodes().item( 1 ) ); + Node firstChild = child.getChildNodes().item( 0 ); + Node secondChild = child.getChildNodes().item( 1 ); + if ( firstChild != null && secondChild != null ) { + if ( firstChild.getNodeName().equals( "#text" ) && !secondChild.getNodeName().equals( "#text" ) ) { + removeNode( child.getChildNodes().item( 1 ) ); + } } + LOGGER.warn( "possible problem while removing formating node" ); continue; } diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index fe3f31c..7e814fa 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -18,6 +18,7 @@ import javax.xml.transform.stream.StreamResult; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.w3c.dom.Element; class VBoxSoundCardMeta { @@ -63,7 +64,6 @@ class VBoxEthernetDevTypeMeta public class VboxMetaData extends VmMetaData { - private static final Logger LOGGER = Logger.getLogger( VboxMetaData.class ); private static final Virtualizer virtualizer = new Virtualizer( "virtualbox", "VirtualBox" ); @@ -72,7 +72,6 @@ public class VboxMetaData extends VmMetaData osList, File file ) throws IOException, UnsupportedVirtualizerFormatException { - super( osList ); this.config = new VboxConfig( file ); init(); @@ -80,7 +79,6 @@ public class VboxMetaData extends VmMetaData osList, byte[] vmContent, int length ) throws IOException, UnsupportedVirtualizerFormatException { - super( osList ); this.config = new VboxConfig( vmContent, length ); init(); @@ -88,6 +86,8 @@ public class VboxMetaData extends VmMetaData protected Map hwversion = new HashMap<>(); protected Map networkCards = new HashMap<>(); + /** + * All the available virtual Sound Cards that are supported by VmxPlayer and VBoxPlayer + * + * @author victorm + * + */ public static enum SoundCardType { NONE( "None" ), @@ -46,6 +52,12 @@ public abstract class VmMetaData } } + /** + * All the available settings for the 3D acceleration that are supported by VmxPlayer and VBoxPlayer + * + * @author victorm + * + */ public static enum DDAcceleration { OFF( "Off" ), @@ -59,7 +71,12 @@ public abstract class VmMetaData } } - // Virtual hardware version + /** + * All the available virtual Hardware Versions that are supported by VmxPlayer and VBoxPlayer + * + * @author victorm + * + */ public static enum HWVersion { NONE( "(invalid)" ), @@ -81,7 +98,12 @@ public abstract class VmMetaData } } - // Virtual network adapter + /** + * All the available virtual Network Cards that are supported by VmxPlayer and VBoxPlayer + * + * @author victorm + * + */ public static enum EthernetDevType { AUTO( "(default)" ), @@ -282,6 +304,7 @@ public abstract class VmMetaData LOGGER.debug( "Machine description not in .vmx format.", e ); } try { + LOGGER.debug( "versuche vbox" ); return new VboxMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { LOGGER.debug( "Machine description not in .vbox format.", e ); @@ -326,5 +349,11 @@ public abstract class VmMetaData public abstract EthernetDevType getEthernetDevType( int cardIndex ); public abstract byte[] getDefinitionArray(); - + + /** + * + * Function used by subclasses to put the virtual devices, which the subclass supports in the respected map + * (i.e. a supported virtual Soundcard in the soundCards Map + */ + public abstract void populateTheMaps(); } diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java index ab180e0..fc4e3b1 100644 --- a/src/main/java/org/openslx/util/vm/VmwareConfig.java +++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java @@ -271,7 +271,5 @@ public class VmwareConfig { this.value = value; } - } - } -- cgit v1.2.3-55-g7522