Search in sources :

Example 1 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project tdi-studio-se by Talend.

the class JobLaunchShortcut method createConfiguration.

/**
     * Creates a new configuration associated with the given file.
     * 
     * @param file
     * @return ILaunchConfiguration
     */
private ILaunchConfiguration createConfiguration(ProcessItem file) {
    ILaunchConfiguration config = null;
    String jobId = file.getProperty().getId();
    String jobName = file.getProperty().getLabel();
    String jobVersion = file.getProperty().getVersion();
    ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE);
    //$NON-NLS-1$
    String displayName = jobName + " " + jobVersion;
    try {
        if (type != null) {
            ILaunchConfigurationWorkingCopy wc = type.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(displayName));
            wc.setAttribute(TalendDebugUIConstants.JOB_NAME, jobName);
            wc.setAttribute(TalendDebugUIConstants.JOB_ID, jobId);
            wc.setAttribute(TalendDebugUIConstants.JOB_VERSION, jobVersion);
            String projectName = ProjectManager.getInstance().getCurrentProject().getLabel();
            wc.setAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, projectName);
            config = wc.doSave();
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 2 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project linuxtools by eclipse.

the class LaunchConfigurationUtils method createDockerComposeUpLaunchConfiguration.

/**
 * Creates an {@link ILaunchConfiguration} for to run the
 * {@code docker-compose up} command.
 *
 * @param connection
 *            the Docker connection to use
 * @param dockerComposeScript
 *            the {@code docker-compose.yml} script
 * @return the created {@link ILaunchConfiguration}
 * @throws CoreException
 *             if something wrong happened when creating the
 *             {@link ILaunchConfiguration}
 */
public static ILaunchConfiguration createDockerComposeUpLaunchConfiguration(final IDockerConnection connection, final IResource dockerComposeScript) throws CoreException {
    final ILaunchConfigurationType configType = LaunchConfigurationUtils.getLaunchConfigType(IDockerComposeLaunchConfigurationConstants.CONFIG_TYPE_ID);
    final ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(createDockerComposeLaunchConfigurationName(dockerComposeScript)));
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR, dockerComposeScript.getFullPath().removeLastSegments(1).toString());
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, true);
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.DOCKER_CONNECTION, connection.getName());
    return wc.doSave();
}
Also used : ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 3 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project linuxtools by eclipse.

the class LaunchConfigurationUtils method createRunImageLaunchConfiguration.

/**
 * Creates a new {@link ILaunchConfiguration} for the given
 * {@link IDockerContainer}.
 *
 * @param baseConfigurationName
 *            the base configuration name to use when creating the
 *            {@link ILaunchConfiguration}.
 * @param image
 *            the {@link IDockerImage} used to create the container
 * @param containerName
 *            the actual container name (given by the user or generated by
 *            the Docker daemon)
 * @param containerConfig
 * @param hostConfig
 *            the user-provided {@link IDockerHostConfig} (created
 *            container's one)
 * @param removeWhenExits
 *            flag to indicate if container should be removed when exited
 * @return the generated {@link ILaunchConfiguration}
 */
public static ILaunchConfiguration createRunImageLaunchConfiguration(final IDockerImage image, final IDockerContainerConfig containerConfig, final IDockerHostConfig hostConfig, final String containerName, final boolean removeWhenExits) {
    try {
        final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        final ILaunchConfigurationType type = manager.getLaunchConfigurationType(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID);
        final String imageName = createRunImageLaunchConfigurationName(image);
        // using the image repo + first tag
        final ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationWorkingCopy(type, imageName);
        workingCopy.setAttribute(CREATION_DATE, DATE_FORMAT.format(new Date()));
        workingCopy.setAttribute(CONNECTION_NAME, image.getConnection().getName());
        workingCopy.setAttribute(IMAGE_ID, image.id());
        workingCopy.setAttribute(IMAGE_NAME, createRunImageLaunchConfigurationName(image));
        if (containerName != null && !containerName.isEmpty()) {
            workingCopy.setAttribute(CONTAINER_NAME, containerName);
        }
        // if we know the raw command string, use it since the container
        // config will remove quotes to split up command properly
        DockerContainerConfig config = (DockerContainerConfig) containerConfig;
        if (config.rawcmd() != null) {
            workingCopy.setAttribute(COMMAND, config.rawcmd());
        } else {
            workingCopy.setAttribute(COMMAND, toString(containerConfig.cmd()));
        }
        workingCopy.setAttribute(ENTRYPOINT, toString(containerConfig.entrypoint()));
        // selected ports
        workingCopy.setAttribute(PUBLISH_ALL_PORTS, hostConfig.publishAllPorts());
        // format: <containerPort><type>:<hostIP>:<hostPort>
        if (hostConfig.publishAllPorts()) {
            final IDockerImageInfo imageInfo = image.getConnection().getImageInfo(image.id());
            if (imageInfo != null) {
                workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(imageInfo.containerConfig().exposedPorts()));
            }
        } else {
            workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(hostConfig.portBindings()));
        }
        // links (with format being: "<containerName>:<containerAlias>")
        workingCopy.setAttribute(LINKS, hostConfig.links());
        // env variables
        workingCopy.setAttribute(ENV_VARIABLES, containerConfig.env());
        // labels
        workingCopy.setAttribute(LABELS, containerConfig.labels());
        // volumes
        final List<String> volumes = new ArrayList<>();
        // volumes from other containers
        for (String volumeFrom : hostConfig.volumesFrom()) {
            final DataVolumeModel volume = DataVolumeModel.parseVolumeFrom(volumeFrom);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // bindings to host directory or file
        for (String bind : hostConfig.binds()) {
            final DataVolumeModel volume = DataVolumeModel.parseHostBinding(bind);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // TODO: container path declaration
        workingCopy.setAttribute(DATA_VOLUMES, volumes);
        // options
        workingCopy.setAttribute(AUTO_REMOVE, removeWhenExits);
        workingCopy.setAttribute(ALLOCATE_PSEUDO_CONSOLE, containerConfig.tty());
        workingCopy.setAttribute(INTERACTIVE, containerConfig.openStdin());
        workingCopy.setAttribute(PRIVILEGED, hostConfig.privileged());
        workingCopy.setAttribute(READONLY, ((DockerHostConfig) hostConfig).readonlyRootfs());
        if (hostConfig.networkMode() != null)
            workingCopy.setAttribute(NETWORK_MODE, hostConfig.networkMode());
        // resources limitations
        if (containerConfig.memory() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            // memory in containerConfig is expressed in bytes
            workingCopy.setAttribute(MEMORY_LIMIT, Long.toString(containerConfig.memory().longValue() / MB));
        }
        if (containerConfig.cpuShares() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            workingCopy.setAttribute(CPU_PRIORITY, containerConfig.cpuShares().toString());
        }
        return workingCopy.doSave();
    } catch (CoreException e) {
        Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, LaunchMessages.getString(// $NON-NLS-1$
        "RunDockerImageLaunchConfiguration.creation.failure"), e));
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DataVolumeModel(org.eclipse.linuxtools.internal.docker.ui.wizards.DataVolumeModel) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Date(java.util.Date)

Example 4 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project linuxtools by eclipse.

the class ModelTest method testRecordString.

@Test
public void testRecordString() throws CoreException {
    ILaunchConfigurationWorkingCopy tempConfig = config.copy("test-config");
    tempConfig.setAttribute(PerfPlugin.ATTR_Record_Realtime, true);
    tempConfig.setAttribute(PerfPlugin.ATTR_Record_Realtime_Priority, 2);
    tempConfig.setAttribute(PerfPlugin.ATTR_Record_Verbose, true);
    tempConfig.setAttribute(PerfPlugin.ATTR_Multiplex, true);
    ArrayList<String> selectedEvents = new ArrayList<>();
    selectedEvents.add("cpu-cycles");
    selectedEvents.add("cache-misses");
    selectedEvents.add("cpu-clock");
    tempConfig.setAttribute(PerfPlugin.ATTR_SelectedEvents, selectedEvents);
    tempConfig.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
    String[] recordString = PerfCore.getRecordString(tempConfig);
    assertNotNull(recordString);
    String[] expectedString = { PerfPlugin.PERF_COMMAND, "record", "-r", "2", "-v", "-M", "-e", "cpu-cycles", "-e", "cache-misses", "-e", "cpu-clock" };
    assertArrayEquals(expectedString, recordString);
}
Also used : ArrayList(java.util.ArrayList) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Test(org.junit.Test) AbstractTest(org.eclipse.linuxtools.profiling.tests.AbstractTest)

Example 5 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project linuxtools by eclipse.

the class ModelTest method testAnnotateString.

@Test
public void testAnnotateString() throws CoreException {
    ILaunchConfigurationWorkingCopy tempConfig = config.copy("test-config");
    tempConfig.setAttribute(PerfPlugin.ATTR_Kernel_Location, "/boot/kernel");
    tempConfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, true);
    String[] annotateString = PerfCore.getAnnotateString(tempConfig, "dso", "symbol", "resources/defaultevent-data/perf.data", false);
    String[] expectedString = new String[] { PerfPlugin.PERF_COMMAND, "annotate", "--stdio", "-d", "dso", "-s", "symbol", "-l", "-P", "--vmlinux", "/boot/kernel", "-m", "-i", "resources/defaultevent-data/perf.data", "<", "/dev/null" };
    assertArrayEquals(expectedString, annotateString);
}
Also used : ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Test(org.junit.Test) AbstractTest(org.eclipse.linuxtools.profiling.tests.AbstractTest)

Aggregations

ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)202 Test (org.junit.Test)79 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)69 ILaunch (org.eclipse.debug.core.ILaunch)58 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)56 IProcess (org.eclipse.debug.core.model.IProcess)53 CoreException (org.eclipse.core.runtime.CoreException)51 ILaunchManager (org.eclipse.debug.core.ILaunchManager)39 IPath (org.eclipse.core.runtime.IPath)20 ArrayList (java.util.ArrayList)17 IProject (org.eclipse.core.resources.IProject)15 Shell (org.eclipse.swt.widgets.Shell)11 Path (org.eclipse.core.runtime.Path)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 AbstractTest (org.eclipse.linuxtools.profiling.tests.AbstractTest)8 HashMap (java.util.HashMap)7 IResource (org.eclipse.core.resources.IResource)7 IOException (java.io.IOException)6 Map (java.util.Map)6