<commit_before>package edu.pitt.apollo.soapjobrunningserviceconnector;

import edu.pitt.apollo.connector.JobRunningServiceConnector;
import edu.pitt.apollo.db.ApolloDbUtils;
import edu.pitt.apollo.db.exceptions.ApolloDatabaseException;
import edu.pitt.apollo.exception.JobRunningServiceException;
import edu.pitt.apollo.exception.JsonUtilsException;
import edu.pitt.apollo.service.simulatorservice.v3_0_0.SimulatorServiceEI;
import edu.pitt.apollo.service.simulatorservice.v3_0_0.SimulatorServiceV300;
import edu.pitt.apollo.service.visualizerservice.v3_0_0.VisualizerServiceEI;
import edu.pitt.apollo.service.visualizerservice.v3_0_0.VisualizerServiceV300;
import edu.pitt.apollo.services_common.v3_0_0.ApolloSoftwareTypeEnum;
import edu.pitt.apollo.services_common.v3_0_0.Authentication;
import edu.pitt.apollo.services_common.v3_0_0.MethodCallStatus;
import edu.pitt.apollo.services_common.v3_0_0.MethodCallStatusEnum;
import edu.pitt.apollo.services_common.v3_0_0.SoftwareIdentification;
import edu.pitt.apollo.services_common.v3_0_0.TerminateRunRequest;
import edu.pitt.apollo.services_common.v3_0_0.TerminteRunResult;
import edu.pitt.apollo.visualizer_service_types.v3_0_0.RunVisualizationMessage;
import java.io.IOException;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.ws.Service;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

/**
 *
 * @author nem41
 */
public class SoapJobRunningServiceConnector extends JobRunningServiceConnector {

	private SoftwareIdentification softwareIdentification;

	public SoapJobRunningServiceConnector(String url, SoftwareIdentification softwareIdentification) throws JobRunningServiceException {
		super(url);
		this.softwareIdentification = softwareIdentification;
	}

	private void initializePort(Service port) throws JobRunningServiceException {
		try {
			// disable chunking for ZSI
			Client simulatorClient = ClientProxy.getClient(port);
			HTTPConduit simulatorHttp = (HTTPConduit) simulatorClient.getConduit();
			HTTPClientPolicy simulatorHttpClientPolicy = new HTTPClientPolicy();
			simulatorHttpClientPolicy.setConnectionTimeout(36000);
			simulatorHttpClientPolicy.setAllowChunking(false);
			simulatorHttp.setClient(simulatorHttpClientPolicy);
		} catch (Exception ex) {
			throw new JobRunningServiceException("Exception getting simulator service endpoint: " + ex.getMessage());
		}
	}

	@Override
	public void run(BigInteger runId, Authentication authentication) throws JobRunningServiceException {

		MethodCallStatus status = null;
		try {
			if (softwareIdentification.getSoftwareType().equals(ApolloSoftwareTypeEnum.SIMULATOR)) {
				SimulatorServiceEI port = new SimulatorServiceV300(new URL(serviceUrl)).getSimulatorServiceEndpoint();
				status = port.runSimulation(runId);
			} else if (softwareIdentification.getSoftwareType().equals(ApolloSoftwareTypeEnum.VISUALIZER)) {
				VisualizerServiceEI port = new VisualizerServiceV300(new URL(serviceUrl)).getVisualizerServiceEndpoint();

				try {
				    // SOAP visualizer requires RunVisualizationMessage as a parameter, not just runID, so we have to load it
					// temporarily we need ApolloDbUtils, should remove this in the future
					ApolloDbUtils dbUtils = new ApolloDbUtils();
					int vizKey;
					if (softwareIdentification.getSoftwareName().toLowerCase().contains("gaia")) {
						vizKey = 5;
					} else {
						vizKey = 4;
					}<commit_msg>minor improvement to temporary visualizer run code<commit_after>package edu.pitt.apollo.soapjobrunningserviceconnector;

import edu.pitt.apollo.connector.JobRunningServiceConnector;
import edu.pitt.apollo.db.ApolloDbUtils;
import edu.pitt.apollo.db.exceptions.ApolloDatabaseException;
import edu.pitt.apollo.exception.JobRunningServiceException;
import edu.pitt.apollo.exception.JsonUtilsException;
import edu.pitt.apollo.service.simulatorservice.v3_0_0.SimulatorServiceEI;
import edu.pitt.apollo.service.simulatorservice.v3_0_0.SimulatorServiceV300;
import edu.pitt.apollo.service.visualizerservice.v3_0_0.VisualizerServiceEI;
import edu.pitt.apollo.service.visualizerservice.v3_0_0.VisualizerServiceV300;
import edu.pitt.apollo.services_common.v3_0_0.ApolloSoftwareTypeEnum;
import edu.pitt.apollo.services_common.v3_0_0.Authentication;
import edu.pitt.apollo.services_common.v3_0_0.MethodCallStatus;
import edu.pitt.apollo.services_common.v3_0_0.MethodCallStatusEnum;
import edu.pitt.apollo.services_common.v3_0_0.SoftwareIdentification;
import edu.pitt.apollo.services_common.v3_0_0.TerminateRunRequest;
import edu.pitt.apollo.services_common.v3_0_0.TerminteRunResult;
import edu.pitt.apollo.visualizer_service_types.v3_0_0.RunVisualizationMessage;
import java.io.IOException;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.ws.Service;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

/**
 *
 * @author nem41
 */
public class SoapJobRunningServiceConnector extends JobRunningServiceConnector {

	private SoftwareIdentification softwareIdentification;

	public SoapJobRunningServiceConnector(String url, SoftwareIdentification softwareIdentification) throws JobRunningServiceException {
		super(url);
		this.softwareIdentification = softwareIdentification;
	}

	private void initializePort(Service port) throws JobRunningServiceException {
		try {
			// disable chunking for ZSI
			Client simulatorClient = ClientProxy.getClient(port);
			HTTPConduit simulatorHttp = (HTTPConduit) simulatorClient.getConduit();
			HTTPClientPolicy simulatorHttpClientPolicy = new HTTPClientPolicy();
			simulatorHttpClientPolicy.setConnectionTimeout(36000);
			simulatorHttpClientPolicy.setAllowChunking(false);
			simulatorHttp.setClient(simulatorHttpClientPolicy);
		} catch (Exception ex) {
			throw new JobRunningServiceException("Exception getting simulator service endpoint: " + ex.getMessage());
		}
	}

	@Override
	public void run(BigInteger runId, Authentication authentication) throws JobRunningServiceException {

		MethodCallStatus status = null;
		try {
			if (softwareIdentification.getSoftwareType().equals(ApolloSoftwareTypeEnum.SIMULATOR)) {
				SimulatorServiceEI port = new SimulatorServiceV300(new URL(serviceUrl)).getSimulatorServiceEndpoint();
				status = port.runSimulation(runId);
			} else if (softwareIdentification.getSoftwareType().equals(ApolloSoftwareTypeEnum.VISUALIZER)) {
				VisualizerServiceEI port = new VisualizerServiceV300(new URL(serviceUrl)).getVisualizerServiceEndpoint();

				try {
				    // SOAP visualizer requires RunVisualizationMessage as a parameter, not just runID, so we have to load it
					// temporarily we need ApolloDbUtils, should remove this in the future
					ApolloDbUtils dbUtils = new ApolloDbUtils();
					int vizKey = dbUtils.getSoftwareIdentificationKey(softwareIdentification);
{'fraction_non_alphanumeric': 0.08313472592177204, 'fraction_numerical': 0.015701668302257114, 'mean_word_length': 6.517386722866175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3640143', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2155, 'n_words': 360}