summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVictor Mocanu2017-11-02 17:12:56 +0100
committerVictor Mocanu2017-11-02 17:12:56 +0100
commit1f58a5c478c82978418cb152ad43a7cc18a002a8 (patch)
treeed26ba585b5e9e6cbd1dfe3c6009be259d74cb8e /src
parent[VBox] added sorting to the keysarrays (diff)
downloadmaster-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.tar.gz
master-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.tar.xz
master-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.zip
[VBox] new working coppy
added new Javadocs, updated getters of VBoxMetaData still got TODOs
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java48
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java104
-rw-r--r--src/main/java/org/openslx/util/vm/VmMetaData.java35
-rw-r--r--src/main/java/org/openslx/util/vm/VmwareConfig.java2
4 files changed, 137 insertions, 52 deletions
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<HardDisk> hddsArray = new ArrayList<HardDisk>();;
+ private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>();
// 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<VBoxSoundCardMeta, VBoxDDAccelMeta, VBoxHWVersionMeta, VBoxEthernetDevTypeMeta>
{
-
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<VBoxSoundCardMeta, VBoxDDAccelMeta,
public VboxMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException
{
-
super( osList );
this.config = new VboxConfig( file );
init();
@@ -80,7 +79,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
public VboxMetaData( List<OperatingSystem> 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<VBoxSoundCardMeta, VBoxDDAccelMeta,
private void init()
{
+ populateTheMaps();
+
this.config.init();
displayName = config.getDisplayName();
setOs( "virtualbox", config.getOsName() );
@@ -95,19 +95,9 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
for ( HardDisk hardDisk : config.getHdds() ) {
hdds.add( hardDisk );
}
-
- // hey debug code here
- try {
- addFloppy( 0, null, true );
- WriteToFile();
- } catch ( TransformerFactoryConfigurationError | TransformerException e ) {
- // WriteToFile exceptions here...not important for the the LOGGER
- e.printStackTrace();
- }
- // end here
}
- // --TODO will be needed later again
+ // TODO DELETE LATER WHEN NOT NEEDED ANYMORE
private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -115,6 +105,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
Source input = new DOMSource( config.getConfigDoc() );
transformer.transform( input, output );
}
+ // TODO END DELETE LATER WHEN NOT NEEDED ANYMORE
@Override
public Virtualizer getVirtualizer()
@@ -270,24 +261,38 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
}
@Override
- public org.openslx.util.vm.VmMetaData.SoundCardType getSoundCard()
+ public VmMetaData.SoundCardType getSoundCard()
{
- // TODO Auto-generated method stub
- return null;
+ VmMetaData.SoundCardType returnsct = null;
+ // TODO ask about controller and driver
+ Element x = (Element) config.findANode( "AudioAdapter" ).item( 0 );
+ returnsct = VmMetaData.SoundCardType.DEFAULT;
+ // TODO End
+ return returnsct;
}
@Override
- public void setDDAcceleration( org.openslx.util.vm.VmMetaData.DDAcceleration type )
+ public void setDDAcceleration( VmMetaData.DDAcceleration type )
{
// TODO Auto-generated method stub
}
@Override
- public org.openslx.util.vm.VmMetaData.DDAcceleration getDDAcceleration()
+ public VmMetaData.DDAcceleration getDDAcceleration()
{
- // TODO Auto-generated method stub
- return null;
+ VmMetaData.DDAcceleration returndda = null;
+ Element x = (Element)config.findANode( "Display" ).item( 0 );
+ if ( x.hasAttribute( "accelerate3D" ) ) {
+ if ( x.getAttribute( "accelerate3D" ).equals( "true" ) ) {
+ returndda = VmMetaData.DDAcceleration.ON;
+ } else {
+ returndda = VmMetaData.DDAcceleration.OFF;
+ }
+ } else {
+ returndda = VmMetaData.DDAcceleration.OFF;
+ }
+ return returndda;
}
@Override
@@ -300,8 +305,11 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
@Override
public HWVersion getHWVersion()
{
- // TODO Auto-generated method stub
- return null;
+ VmMetaData.HWVersion returnhwv = null;
+ // TODO what do here? there is only one supported hwversion as far as I know
+ returnhwv = VmMetaData.HWVersion.NONE;
+ // TODO End
+ return returnhwv;
}
@Override
@@ -314,14 +322,56 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
@Override
public EthernetDevType getEthernetDevType( int cardIndex )
{
- // TODO Auto-generated method stub
- return null;
+ VmMetaData.EthernetDevType returnedt = null;
+ // TODO what do here?
+ // TODO need to search for the 1.st adapter of network tag
+ return VmMetaData.EthernetDevType.AUTO;
}
@Override
public byte[] getDefinitionArray()
{
- // TODO Auto-generated method stub
- return null;
+ return config.toString().getBytes( StandardCharsets.UTF_8 );
+ }
+
+ public void populateTheMaps()
+ {
+ /* add all from VBox supported sound cards here
+ soundCards.put( VmMetaData.SoundCardType.NONE, new VBoxSoundCardMeta( false, null ) );
+ soundCards.put( VmMetaData.SoundCardType.HD_AUDIO, new VBoxSoundCardMeta( true, "hdaudio" ) );
+ // end of supported sound cards
+ // add all from VBox supported settings for the 3D acceleration
+ ddacc.put( VmMetaData.DDAcceleration.ON, new VBoxDDAccelMeta( true ) );
+ ddacc.put( VmMetaData.DDAcceleration.OFF, new VBoxDDAccelMeta( false ) );
+ // end of all from VBox supported settings for the 3D acceleration
+ // add all from VBox supported Hardware versions here
+ hwversion.put( VmMetaData.HWVersion.NONE, new VBoxHWVersionMeta( 0 ) );
+ // end of all from VBox supported Hardware versions here
+ // add all from VBox supported Ethernet devices versions here
+ networkCards.put( VmMetaData.EthernetDevType.E1000, new VBoxEthernetDevTypeMeta( "e1000" ) );
+ // end of all from VBox supported Ethernet devices versions here */
+
+ // add all from vmware supported sound cards here
+ soundCards.put( VmMetaData.SoundCardType.NONE, new VBoxSoundCardMeta( false, null ) );
+ soundCards.put( VmMetaData.SoundCardType.DEFAULT, new VBoxSoundCardMeta( true, null ) );
+ soundCards.put( VmMetaData.SoundCardType.SOUND_BLASTER, new VBoxSoundCardMeta( true, "sb16" ) );
+ soundCards.put( VmMetaData.SoundCardType.ES, new VBoxSoundCardMeta( true, "es1371" ) );
+ soundCards.put( VmMetaData.SoundCardType.HD_AUDIO, new VBoxSoundCardMeta( true, "hdaudio" ) );
+ // end of supported sound cards
+ // add all from vmware supported settings for the 3D acceleration
+ ddacc.put( VmMetaData.DDAcceleration.OFF, new VBoxDDAccelMeta( false ) );
+ ddacc.put( VmMetaData.DDAcceleration.ON, new VBoxDDAccelMeta( true ) );
+ // end of all from vmware supported settings for the 3D acceleration
+ // add all from vmware supported Hardware versions here
+ hwversion.put( VmMetaData.HWVersion.NONE, new VBoxHWVersionMeta( 0 ) );
+ hwversion.put( VmMetaData.HWVersion.THREE, new VBoxHWVersionMeta( 3 ) );
+ hwversion.put( VmMetaData.HWVersion.FOUR, new VBoxHWVersionMeta( 4 ) );
+
+ // end of all from vmware supported Hardware versions here
+ // add all from vmware supported Ethernet devices versions here
+ networkCards.put( VmMetaData.EthernetDevType.AUTO, new VBoxEthernetDevTypeMeta( null ) );
+ networkCards.put( VmMetaData.EthernetDevType.PCNET32, new VBoxEthernetDevTypeMeta( "vlance" ) );
+ networkCards.put( VmMetaData.EthernetDevType.E1000, new VBoxEthernetDevTypeMeta( "e1000" ) );
+ // end of all from vmware supported Ethernet devices versions here
}
}
diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java
index 36ecd4c..5529c63 100644
--- a/src/main/java/org/openslx/util/vm/VmMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmMetaData.java
@@ -30,6 +30,12 @@ public abstract class VmMetaData<T, U, V, W>
protected Map<HWVersion, V> hwversion = new HashMap<>();
protected Map<EthernetDevType, W> networkCards = new HashMap<>();
+ /**
+ * All the available virtual Sound Cards that are supported by VmxPlayer and VBoxPlayer
+ * <add further entries when incorporating other Virtualizers>
+ * @author victorm
+ *
+ */
public static enum SoundCardType
{
NONE( "None" ),
@@ -46,6 +52,12 @@ public abstract class VmMetaData<T, U, V, W>
}
}
+ /**
+ * All the available settings for the 3D acceleration that are supported by VmxPlayer and VBoxPlayer
+ * <add further entries when incorporating other Virtualizers>
+ * @author victorm
+ *
+ */
public static enum DDAcceleration
{
OFF( "Off" ),
@@ -59,7 +71,12 @@ public abstract class VmMetaData<T, U, V, W>
}
}
- // Virtual hardware version
+ /**
+ * All the available virtual Hardware Versions that are supported by VmxPlayer and VBoxPlayer
+ * <add further entries when incorporating other Virtualizers>
+ * @author victorm
+ *
+ */
public static enum HWVersion
{
NONE( "(invalid)" ),
@@ -81,7 +98,12 @@ public abstract class VmMetaData<T, U, V, W>
}
}
- // Virtual network adapter
+ /**
+ * All the available virtual Network Cards that are supported by VmxPlayer and VBoxPlayer
+ * <add further entries when incorporating other Virtualizers>
+ * @author victorm
+ *
+ */
public static enum EthernetDevType
{
AUTO( "(default)" ),
@@ -282,6 +304,7 @@ public abstract class VmMetaData<T, U, V, W>
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<T, U, V, W>
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;
}
-
}
-
}