summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericWrapperScript.java
blob: 60c98d4729f2d1010d90119e040478350d8e4fc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.openslx.runvirt.plugin.qemu.configuration;

import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslx.libvirt.domain.Domain;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.util.Util;
import org.openslx.virtualization.configuration.transformation.TransformationException;
import org.openslx.virtualization.configuration.transformation.TransformationGeneric;

/**
 * Use openslx wrapper script for launching the emulator (virtualizer)
 * 
 * @author sr
 */
public class TransformationGenericWrapperScript extends TransformationGeneric<Domain, CommandLineArgs>
{
	/**
	 * Instance of a logger to log messages.
	 */
	private static final Logger LOGGER = LogManager.getLogger( TransformationGenericWrapperScript.class );

	/**
	 * Name of the configuration transformation.
	 */
	private static final String NAME = "Use wrapper script for emulator if found";

	/**
	 * Extension for the wrapper we look for
	 */
	private static final String WRAPPER_EXT = ".openslx";

	public TransformationGenericWrapperScript()
	{
		super( TransformationGenericWrapperScript.NAME );
	}

	/**
	 * Validates a virtualization configuration and input arguments for this transformation.
	 */
	private void validateInputs( Domain config, CommandLineArgs args ) throws TransformationException
	{
		if ( config == null || args == null ) {
			throw new TransformationException( "Virtualization configuration or input arguments are missing!" );
		}
	}

	@Override
	public void transform( Domain config, CommandLineArgs args ) throws TransformationException
	{
		// validate configuration and input arguments
		this.validateInputs( config, args );

		// Use our wrapper if it exists
		String emu = config.getDevicesEmulator();
		if ( !Util.isEmptyString( emu ) && new File( emu + WRAPPER_EXT ).canExecute() ) {
			LOGGER.info( "Using emulator wrapper " + emu + WRAPPER_EXT );
			config.setDevicesEmulator( emu + WRAPPER_EXT );
		}
	}
}