summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxMetaData.java
diff options
context:
space:
mode:
authorJonathan Bauer2017-10-20 17:48:24 +0200
committerJonathan Bauer2017-10-20 17:48:24 +0200
commit17a212b54f42c46f203abbbcea61a80d6f40df61 (patch)
tree338659b194a09c377cdce914719b741a285b7ea7 /src/main/java/org/openslx/util/vm/VboxMetaData.java
parent[VBox] improved download part (diff)
downloadmaster-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.tar.gz
master-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.tar.xz
master-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.zip
formatting & first round of cleanup
removed typeOf, use instanceof
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxMetaData.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java163
1 files changed, 70 insertions, 93 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java
index 5115248..9ea59d2 100644
--- a/src/main/java/org/openslx/util/vm/VboxMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java
@@ -19,209 +19,186 @@ import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
-public class VboxMetaData extends VmMetaData
-{
- private static final Logger LOGGER = Logger.getLogger( VboxMetaData.class );
- private static final Virtualizer virtualizer = new Virtualizer( "virtualbox", "VirtualBox" );
+public class VboxMetaData extends VmMetaData {
- private final VboxConfig config;
+ private static final Logger LOGGER = Logger.getLogger(VboxMetaData.class);
+
+ private static final Virtualizer virtualizer = new Virtualizer("virtualbox", "VirtualBox");
- public VboxMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException
- {
- super( osList );
+ private final VboxConfig config;
- this.config = new VboxConfig( file );
+ public VboxMetaData(List<OperatingSystem> osList, File file)
+ throws IOException, UnsupportedVirtualizerFormatException {
+ super(osList);
+ this.config = new VboxConfig(file);
init();
}
- public VboxMetaData( List<OperatingSystem> osList, byte[] vmContent, int length ) throws IOException, UnsupportedVirtualizerFormatException
- {
- super( osList );
- this.config = new VboxConfig( vmContent, length );
- setTypeOf();
- init();
+ public VboxMetaData(List<OperatingSystem> osList, byte[] vmContent, int length)
+ throws IOException, UnsupportedVirtualizerFormatException {
+ super(osList);
+ this.config = new VboxConfig(vmContent, length);
+ init();
}
- private void init()
- {
+ private void init() {
this.config.init();
-
displayName = config.getDisplayName();
+ setOs("virtualbox", config.getOsName());
- setOs( "virtualbox", config.getOsName() );
-
- for ( HardDisk hardDisk : config.getHdds() ) {
- hdds.add( hardDisk );
+ for (HardDisk hardDisk : config.getHdds()) {
+ hdds.add(hardDisk);
}
+
+ // DEBUG Code???? mark such code please!
try {
- addFloppy( 0, null, true );
+ addFloppy(0, null, true);
WriteToFile();
- } catch ( TransformerFactoryConfigurationError | TransformerException e ) {
+ } catch (TransformerFactoryConfigurationError | TransformerException e) {
// WriteToFile exceptions here...not important for the the LOGGER
e.printStackTrace();
}
}
// --TODO will be needed later again
- private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException
- {
+ private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
- StreamResult output = new StreamResult( new File( "output.xml" ) );
- Source input = new DOMSource( config.getConfigDoc() );
- transformer.transform( input, output );
+ StreamResult output = new StreamResult(new File("output.xml"));
+ Source input = new DOMSource(config.getConfigDoc());
+ transformer.transform(input, output);
}
@Override
- public Virtualizer getVirtualizer()
- {
- return new Virtualizer( "virtualbox", "VirtualBox" );
+ public Virtualizer getVirtualizer() {
+ return virtualizer;
}
@Override
- public void enableUsb( boolean enabled )
- {
+ public void enableUsb(boolean enabled) {
// TODO Auto-generated method stub
}
@Override
- public void applySettingsForLocalEdit()
- {
+ public void applySettingsForLocalEdit() {
// TODO Auto-generated method stub
}
@Override
- public byte[] getFilteredDefinitionArray()
- {
- return config.toString().getBytes( StandardCharsets.UTF_8 );
+ public byte[] getFilteredDefinitionArray() {
+ return config.toString().getBytes(StandardCharsets.UTF_8);
}
@Override
- public boolean addHddTemplate( String diskImage, String hddMode, String redoDir )
- {
- config.changeAttribute( "HardDisk", "location", diskImage );
+ public boolean addHddTemplate(String diskImage, String hddMode, String redoDir) {
+ config.changeAttribute("HardDisk", "location", diskImage);
return true;
}
@Override
- public boolean addHddTemplate( File diskImage, String hddMode, String redoDir )
- {
+ public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) {
String diskImagePath = diskImage.getName();
- config.changeAttribute( "HardDisk", "location", diskImagePath );
+ config.changeAttribute("HardDisk", "location", diskImagePath);
UUID newhdduuid = UUID.randomUUID();
- LOGGER.debug( newhdduuid );
+ LOGGER.debug(newhdduuid);
// patching the new uuid in the vbox config file here
String vboxUUid = "{" + newhdduuid.toString() + "}";
- config.changeAttribute( "HardDisk", "uuid", vboxUUid );
- config.changeAttribute( "Image", "uuid", vboxUUid );
+ config.changeAttribute("HardDisk", "uuid", vboxUUid);
+ config.changeAttribute("Image", "uuid", vboxUUid);
// write the new hdd uuid in the vdi file
- byte[] bytesToWrite = new byte[ 16 ];
-
- int[] bytesOffset = {32, 40, 48, 56, 16, 24, 0, 8, 56, 48, 40, 32, 24, 16, 8, 0};
-
+ byte[] bytesToWrite = new byte[16];
+
+ int[] bytesOffset = { 32, 40, 48, 56, 16, 24, 0, 8, 56, 48, 40, 32, 24, 16, 8, 0 };
+
int offset = 0;
for (int i = 0; i < 2; i++) {
Long uuidlong = null;
- if ( i == 0 ) {
+ if (i == 0) {
uuidlong = newhdduuid.getMostSignificantBits();
} else {
uuidlong = newhdduuid.getLeastSignificantBits();
}
-
- for ( int j = 0; j < 8; j++) {
+
+ for (int j = 0; j < 8; j++) {
int index = j + offset;
bytesToWrite[index] = (byte) (uuidlong >>> bytesOffset[index]);
}
offset = 8;
}
- try ( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) {
+ try (RandomAccessFile file = new RandomAccessFile(diskImage, "rw")) {
- file.seek( 392 );
- file.write( bytesToWrite, 0, 16 );
- } catch ( Exception e ) {
- LOGGER.warn( "could not patch new uuid in the vdi", e );
+ file.seek(392);
+ file.write(bytesToWrite, 0, 16);
+ } catch (Exception e) {
+ LOGGER.warn("could not patch new uuid in the vdi", e);
}
-
- // we need a new machine uuid
+
+ // we need a new machine uuid
UUID newMachineUuid = UUID.randomUUID();
- if ( newMachineUuid.equals( newhdduuid ) ) {
- LOGGER.warn( "The new Machine UUID is the same as the new HDD UUID; tying again...this vm might not start" );
+ if (newMachineUuid.equals(newhdduuid)) {
+ LOGGER.warn("The new Machine UUID is the same as the new HDD UUID; tying again...this vm might not start");
newMachineUuid = UUID.randomUUID();
}
String machineUUid = "{" + newMachineUuid.toString() + "}";
- config.changeAttribute( "Machine", "uuid", machineUUid );
+ config.changeAttribute("Machine", "uuid", machineUUid);
return true;
}
@Override
- public boolean addDefaultNat()
- {
- config.addNewNode( "Adapter", "NAT", false );
+ public boolean addDefaultNat() {
+ config.addNewNode("Adapter", "NAT", false);
return true;
}
- public void reWrite()
- {
+ public void reWrite() {
try {
WriteToFile();
- } catch ( TransformerFactoryConfigurationError | TransformerException e ) {
+ } catch (TransformerFactoryConfigurationError | TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
- public void setOs( String vendorOsId )
- {
+ public void setOs(String vendorOsId) {
// TODO Auto-generated method stub
}
@Override
- public boolean addDisplayName( String name )
- {
- config.changeAttribute( "Machine", "name", name );
+ public boolean addDisplayName(String name) {
+ config.changeAttribute("Machine", "name", name);
return true;
}
@Override
- public boolean addRam( int mem )
- {
- config.changeAttribute( "Memory", "RAMSize", Integer.toString( mem ) );
+ public boolean addRam(int mem) {
+ config.changeAttribute("Memory", "RAMSize", Integer.toString(mem));
return true;
}
@Override
- public void addFloppy( int index, String image, boolean readOnly )
- {
+ public void addFloppy(int index, String image, boolean readOnly) {
- if ( image == null ) {
+ if (image == null) {
} else {
}
}
@Override
- public boolean addCdrom( String image )
- {
+ public boolean addCdrom(String image) {
// TODO Auto-generated method stub
return false;
}
@Override
- public void setTypeOf()
- {
- typeOf = TypeOf.VBOX;
- }
-
- @Override
- public boolean addCpuCoreCount( int nrOfCores )
- {
- config.changeAttribute( "CPU", "count", "1" );
+ public boolean addCpuCoreCount(int nrOfCores) {
+ config.changeAttribute("CPU", "count", "1");
return true;
}
}