use of com.intellij.execution.runners.ExecutionEnvironment in project azure-tools-for-java by Microsoft.
the class SparkBatchJobDebuggerRunner method forkEnvironment.
/*
* Build a child environment with specified host and type
*/
private ExecutionEnvironment forkEnvironment(@NotNull final ExecutionEnvironment parentEnv, final String host, final boolean isDriver) {
final String savedProfileName = parentEnv.getUserData(ProfileNameKey);
final String originProfileName = savedProfileName == null ? parentEnv.getRunProfile().getName() : savedProfileName;
final RunConfiguration newRunConfiguration = ((RunConfiguration) parentEnv.getRunProfile()).clone();
newRunConfiguration.setName(originProfileName + " [" + (isDriver ? "Driver " : "Executor ") + host + "]");
final ExecutionEnvironment childEnv = new ExecutionEnvironmentBuilder(parentEnv).runProfile(newRunConfiguration).build();
childEnv.putUserData(DEBUG_TARGET_KEY, isDriver ? DEBUG_DRIVER : DEBUG_EXECUTOR);
childEnv.putUserData(ProfileNameKey, originProfileName);
return childEnv;
}
use of com.intellij.execution.runners.ExecutionEnvironment in project azure-tools-for-java by Microsoft.
the class LivySparkBatchJobRunConfiguration method getState.
@Nullable
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment executionEnvironment) throws ExecutionException {
Operation operation = executionEnvironment.getUserData(TelemetryKeys.OPERATION);
final String debugTarget = executionEnvironment.getUserData(SparkBatchJobDebuggerRunner.DEBUG_TARGET_KEY);
final boolean isExecutor = StringUtils.equals(debugTarget, SparkBatchJobDebuggerRunner.DEBUG_EXECUTOR);
RunProfileStateWithAppInsightsEvent state = null;
final Artifact selectedArtifact = ArtifactUtil.getArtifactWithOutputPaths(getProject()).stream().filter(artifact -> artifact.getName().equals(getSubmitModel().getArtifactName())).findFirst().orElse(null);
if (executor instanceof SparkBatchJobDebugExecutor) {
final ISparkBatchJob remoteDebugBatch = sparkRemoteBatch;
if (!(remoteDebugBatch instanceof SparkBatchRemoteDebugJob)) {
throw new ExecutionException("Spark Batch Job is not prepared for " + executor.getId());
}
if (isExecutor) {
setRunMode(RunMode.REMOTE_DEBUG_EXECUTOR);
state = new SparkBatchRemoteDebugExecutorState(getModel().getSubmitModel(), operation, remoteDebugBatch);
} else {
if (selectedArtifact != null) {
BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(getProject(), this, selectedArtifact);
}
setRunMode(RunMode.REMOTE);
state = new SparkBatchRemoteDebugState(getModel().getSubmitModel(), operation, sparkRemoteBatch);
}
} else if (executor instanceof SparkBatchJobRunExecutor) {
final ISparkBatchJob remoteBatch = sparkRemoteBatch;
if (remoteBatch == null) {
throw new ExecutionException("Spark Batch Job is not prepared for " + executor.getId());
}
if (selectedArtifact != null) {
BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(getProject(), this, selectedArtifact);
}
setRunMode(RunMode.REMOTE);
state = new SparkBatchRemoteRunState(getModel().getSubmitModel(), operation, remoteBatch);
} else if (executor instanceof DefaultDebugExecutor) {
setRunMode(RunMode.LOCAL);
if (operation == null) {
operation = TelemetryManager.createOperation(TelemetryConstants.HDINSIGHT, TelemetryConstants.DEBUG_LOCAL_SPARK_JOB);
operation.start();
}
state = new SparkBatchLocalDebugState(getProject(), getModel().getLocalRunConfigurableModel(), operation);
} else if (executor instanceof DefaultRunExecutor) {
setRunMode(RunMode.LOCAL);
if (operation == null) {
operation = TelemetryManager.createOperation(TelemetryConstants.HDINSIGHT, TelemetryConstants.RUN_LOCAL_SPARK_JOB);
operation.start();
}
state = new SparkBatchLocalRunState(getProject(), getModel().getLocalRunConfigurableModel(), operation);
}
if (state != null) {
final Map<String, String> props = getActionProperties().entrySet().stream().collect(Collectors.toMap((Map.Entry<Object, Object> entry) -> entry.getKey() == null ? null : entry.getKey().toString(), (Map.Entry<Object, Object> entry) -> entry.getValue() == null ? "" : entry.getValue().toString()));
final String configurationId = Optional.ofNullable(executionEnvironment.getRunnerAndConfigurationSettings()).map(settings -> settings.getType().getId()).orElse("");
props.put("configurationId", configurationId);
state.createAppInsightEvent(executor, props);
EventUtil.logEvent(EventType.info, operation, props);
// Clear the action properties
getActionProperties().clear();
}
return state;
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij by bazelbuild.
the class ClassFileManifestBuilder method buildManifest.
/**
* Builds a .class file manifest, then diffs against any previously calculated manifest for this
* debugging session.
*
* @return null if no diff is available (either no manifest could be calculated, or no previously
* calculated manifest is available.
*/
@Nullable
public static ClassFileManifest.Diff buildManifest(ExecutionEnvironment env, @Nullable HotSwapProgress progress) throws ExecutionException {
if (!HotSwapUtils.canHotSwap(env)) {
return null;
}
BlazeCommandRunConfiguration configuration = getConfiguration(env);
Project project = configuration.getProject();
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
throw new ExecutionException("Not synced yet; please sync project");
}
JavaClasspathAspectStrategy aspectStrategy = JavaClasspathAspectStrategy.findStrategy(projectData.blazeVersionData);
if (aspectStrategy == null) {
return null;
}
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, aspectStrategy.getBuildFlags(), ImmutableList.of(), "Building debug binary");
if (progress != null) {
progress.setCancelWorker(() -> buildOperation.cancel(true));
}
try {
SaveUtil.saveAllFiles();
BuildResult result = buildOperation.get();
if (result.status != BuildResult.Status.SUCCESS) {
throw new ExecutionException("Blaze failure building debug binary");
}
} catch (InterruptedException | CancellationException e) {
buildOperation.cancel(true);
throw new RunCanceledByUserException();
} catch (java.util.concurrent.ExecutionException e) {
throw new ExecutionException(e);
}
ImmutableList<File> jars = buildResultHelper.getArtifactsForOutputGroups(ImmutableSet.of(JavaClasspathAspectStrategy.OUTPUT_GROUP)).stream().filter(f -> f.getName().endsWith(".jar")).collect(toImmutableList());
ClassFileManifest oldManifest = getManifest(env);
ClassFileManifest newManifest = ClassFileManifest.build(jars, oldManifest);
env.getCopyableUserData(MANIFEST_KEY).set(newManifest);
return oldManifest != null ? ClassFileManifest.modifiedClasses(oldManifest, newManifest) : null;
}
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij by bazelbuild.
the class BlazeHotSwapManager method findHotSwappableBlazeDebuggerSession.
@Nullable
static HotSwappableDebugSession findHotSwappableBlazeDebuggerSession(Project project) {
DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
DebuggerSession session = debuggerManager.getContext().getDebuggerSession();
if (session == null || !session.isAttached()) {
return null;
}
JavaDebugProcess process = session.getProcess().getXdebugProcess();
if (process == null) {
return null;
}
ExecutionEnvironment env = ((XDebugSessionImpl) process.getSession()).getExecutionEnvironment();
if (env == null || ClassFileManifestBuilder.getManifest(env) == null) {
return null;
}
RunProfile runProfile = env.getRunProfile();
if (!(runProfile instanceof BlazeCommandRunConfiguration)) {
return null;
}
return new HotSwappableDebugSession(session, env, (BlazeCommandRunConfiguration) runProfile);
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij by bazelbuild.
the class ConnectBlazeTestDebuggerTask method launchDebugger.
/**
* Nearly a clone of {@link ConnectJavaDebuggerTask#launchDebugger}. There are a few changes to
* account for null variables that could occur in our implementation.
*/
@Override
public ProcessHandler launchDebugger(@NotNull LaunchInfo currentLaunchInfo, @NotNull Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) {
String debugPort = Integer.toString(client.getDebuggerListenPort());
int pid = client.getClientData().getPid();
Logger.getInstance(ConnectJavaDebuggerTask.class).info(String.format(Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid));
// create a new process handler
RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false);
RemoteDebugProcessHandler debugProcessHandler = new RemoteDebugProcessHandler(project);
// switch the launch status and console printers to point to the new process handler
// this is required, esp. for AndroidTestListener which holds a
// reference to the launch status and printers, and those should
// be updated to point to the new process handlers,
// otherwise test results will not be forwarded appropriately
ProcessHandler oldProcessHandler = launchStatus.getProcessHandler();
launchStatus.setProcessHandler(debugProcessHandler);
printer.setProcessHandler(debugProcessHandler);
// Detach old process handler after the launch status
// has been updated to point to the new process handler.
oldProcessHandler.detachProcess();
AndroidDebugState debugState = new AndroidDebugState(project, debugProcessHandler, connection, currentLaunchInfo.consoleProvider);
RunContentDescriptor oldDescriptor;
AndroidSessionInfo oldSession = oldProcessHandler.getUserData(AndroidSessionInfo.KEY);
if (oldSession != null) {
oldDescriptor = oldSession.getDescriptor();
} else {
// This is the first time we are attaching the debugger; get it from the environment instead.
oldDescriptor = currentLaunchInfo.env.getContentToReuse();
}
RunContentDescriptor debugDescriptor;
try {
// @formatter:off
ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env).executor(currentLaunchInfo.executor).runner(currentLaunchInfo.runner).contentToReuse(oldDescriptor).build();
debugDescriptor = DebuggerPanelsManager.getInstance(project).attachVirtualMachine(debugEnv, debugState, connection, false);
// @formatter:on
} catch (ExecutionException e) {
printer.stderr("ExecutionException: " + e.getMessage() + '.');
return null;
}
// Based on the above try block we shouldn't get here unless we have assigned to debugDescriptor
assert debugDescriptor != null;
// re-run the collected text from the old process handler to the new
// TODO: is there a race between messages received once the debugger has been connected,
// and these messages that are printed out?
final AndroidProcessText oldText = AndroidProcessText.get(oldProcessHandler);
if (oldText != null) {
oldText.printTo(debugProcessHandler);
}
RunProfile runProfile = currentLaunchInfo.env.getRunProfile();
int uniqueId = runProfile instanceof AndroidRunConfigurationBase ? ((AndroidRunConfigurationBase) runProfile).getUniqueID() : -1;
AndroidSessionInfo value = new AndroidSessionInfo(debugProcessHandler, debugDescriptor, uniqueId, currentLaunchInfo.executor.getId(), currentLaunchInfo.executor.getActionName(), false);
debugProcessHandler.putUserData(AndroidSessionInfo.KEY, value);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion());
return debugProcessHandler;
}
Aggregations