<commit_before>package alien4cloud.paas.cloudify3.util;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import alien4cloud.common.AlienConstants;
import alien4cloud.it.Context;
import alien4cloud.model.deployment.DeploymentTopology;
import alien4cloud.model.orchestrators.locations.Location;
import alien4cloud.model.topology.Topology;
import alien4cloud.paas.IPaaSCallback;
import alien4cloud.paas.cloudify3.CloudifyOrchestrator;
import alien4cloud.paas.cloudify3.configuration.CloudConfiguration;
import alien4cloud.paas.cloudify3.configuration.CloudConfigurationHolder;
import alien4cloud.paas.cloudify3.restclient.BlueprintClient;
import alien4cloud.paas.exception.PluginConfigurationException;
import alien4cloud.paas.model.PaaSTopologyDeploymentContext;
import alien4cloud.paas.plan.TopologyTreeBuilderService;
import alien4cloud.paas.wf.WorkflowsBuilderService;
import alien4cloud.paas.wf.WorkflowsBuilderService.TopologyContext;
import alien4cloud.utils.ReflectionUtil;

import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;

@Component
public class DeploymentLauncher {

    @Resource
    private ApplicationUtil applicationUtil;

    @Resource
    private TopologyTreeBuilderService topologyTreeBuilderService;

    @Resource
    private CloudifyOrchestrator cloudifyPaaSProvider;

    @Resource
    private WorkflowsBuilderService workflowBuilderService;

    @Resource
    private CloudConfigurationHolder cloudConfigurationHolder;

    @Resource
    private BlueprintClient blueprintDAO;

    private boolean initialized = false;

    public synchronized void initializeCloudifyManagerConnection() throws PluginConfigurationException {
        // Lazily initialize cloudify connection as test does not need this
        // It's for people who use TestDeploymentService to perform manual testing
        if (initialized) {
            return;
        }
        CloudConfiguration cloudConfiguration = cloudConfigurationHolder.getConfiguration();
        String cloudifyURL = System.getenv("CLOUDIFY_URL");
        if (cloudifyURL == null) {
            cloudifyURL = Context.getInstance().getCloudify3ManagerUrl();
        }
        cloudConfiguration.setUrl(cloudifyURL);
        cloudConfiguration.setUserName("admin");
        cloudConfiguration.setPassword("<PASSWORD>");
        cloudConfiguration.setDisableSSLVerification(true);
        cloudConfigurationHolder.setConfigurationAndNotifyListeners(cloudConfiguration);
        initialized = true;
    }

    public PaaSTopologyDeploymentContext buildPaaSDeploymentContext(String appName, String topologyName, String locationName) {
        return buildPaaSDeploymentContext(appName, topologyName, locationName, null);
    }

    public PaaSTopologyDeploymentContext buildPaaSDeploymentContext(String appName, String topologyName, String locationName,
            Map<String, String> deploymentProperties) {
        Topology topology = applicationUtil.createAlienApplication(appName, topologyName, locationName);
        // init the workflows
        TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology);
        workflowBuilderService.initWorkflows(topologyContext);
        DeploymentTopology deploymentTopology = new DeploymentTopology();
        ReflectionUtil.mergeObject(topology, deploymentTopology, "id");
        PaaSTopologyDeploymentContext deploymentContext = new PaaSTopologyDeploymentContext();
        deploymentContext.setPaaSTopology(topologyTreeBuilderService.buildPaaSTopology(topology));
        deploymentContext.setDeploymentTopology(deploymentTopology);
        alien4cloud.model.deployment.Deployment deployment = new alien4cloud.model.deployment.Deployment();
        deployment.setId(appName);
        deployment.setOrchestratorDeploymentId(appName);
        deploymentContext.setDeployment(deployment);
        Map<String, Location> locationMap = Maps.newHashMap();
        Location location = new Location();
        location.setInfrastructureType(locationName);
        locationMap.put(AlienConstants.GROUP_ALL, location);
        deploymentContext.setLocations(locationMap);

        deploymentTopology.setProviderDeploymentProperties(deploymentProperties);
        return deploymentContext;
    }

    public void launch(PaaSTopologyDeploymentContext deploymentContext) throws Exception {
        initializeCloudifyManagerConnection();
        final SettableFuture<Object> future = SettableFuture.create();
        cloudifyPaaSProvider.deploy(deploymentContext, new IPaaSCallback<Object>() {

            @Override
            public void onSuccess(Object data) {
                future.set(data);
            }

            @Override
            public void onFailure(Throwable throwable) {
                future.setException(throwable);
            }
        });
        future.get();
    }

    public String launch(String topologyName) throws Exception {
        return launch(topologyName, null);
    }

    public String launch(String topologyName, Map<String, String> deploymentProperties) throws Exception {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        String deploymentId = stackTraceElements[2].getMethodName();
        launch(buildPaaSDeploymentContext(deploymentId, topologyName, "amazon", deploymentProperties));
        return deploymentId;
    }

    public void verifyBlueprintUpload(String topology, String path) throws PluginConfigurationException {
        initializeCloudifyManagerConnection();
        // Check if cloudify accept the blueprint
        blueprintDAO.create(topology, path);
        blueprintDAO.delete(topology);
    }
}
<commit_msg>removed unused method<commit_after>package alien4cloud.paas.cloudify3.util;

import alien4cloud.common.AlienConstants;
import alien4cloud.model.deployment.DeploymentTopology;
import alien4cloud.model.orchestrators.locations.Location;
import alien4cloud.model.topology.Topology;
import alien4cloud.paas.IPaaSCallback;
import alien4cloud.paas.cloudify3.CloudifyOrchestrator;
import alien4cloud.paas.cloudify3.configuration.CloudConfiguration;
import alien4cloud.paas.cloudify3.configuration.CloudConfigurationHolder;
import alien4cloud.paas.cloudify3.restclient.BlueprintClient;
import alien4cloud.paas.exception.PluginConfigurationException;
import alien4cloud.paas.model.PaaSTopologyDeploymentContext;
import alien4cloud.paas.plan.TopologyTreeBuilderService;
import alien4cloud.paas.wf.WorkflowsBuilderService;
import alien4cloud.paas.wf.WorkflowsBuilderService.TopologyContext;
import alien4cloud.utils.ReflectionUtil;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class DeploymentLauncher {

    @Resource
    private ApplicationUtil applicationUtil;

    @Resource
    private TopologyTreeBuilderService topologyTreeBuilderService;

    @Resource
    private CloudifyOrchestrator cloudifyPaaSProvider;

    @Resource
    private WorkflowsBuilderService workflowBuilderService;

    @Resource
    private CloudConfigurationHolder cloudConfigurationHolder;

    @Resource
    private BlueprintClient blueprintDAO;

    private boolean initialized = false;

    public synchronized void initializeCloudifyManagerConnection() throws PluginConfigurationException {
        // Lazily initialize cloudify connection as test does not need this
        // It's for people who use TestDeploymentService to perform manual testing
        if (initialized) {
            return;
        }
        CloudConfiguration cloudConfiguration = cloudConfigurationHolder.getConfiguration();
        String cloudifyURL = System.getenv("CLOUDIFY_URL");
        cloudConfiguration.setUrl(cloudifyURL);
        cloudConfiguration.setUserName("admin");
        cloudConfiguration.setPassword("<PASSWORD>");
        cloudConfiguration.setDisableSSLVerification(true);
        cloudConfigurationHolder.setConfigurationAndNotifyListeners(cloudConfiguration);
        initialized = true;
    }

    public PaaSTopologyDeploymentContext buildPaaSDeploymentContext(String appName, String topologyName, String locationName) {
        return buildPaaSDeploymentContext(appName, topologyName, locationName, null);
    }

    public PaaSTopologyDeploymentContext buildPaaSDeploymentContext(String appName, String topologyName, String locationName,
            Map<String, String> deploymentProperties) {
        Topology topology = applicationUtil.createAlienApplication(appName, topologyName, locationName);
        // init the workflows
        TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology);
        workflowBuilderService.initWorkflows(topologyContext);
        DeploymentTopology deploymentTopology = new DeploymentTopology();
        ReflectionUtil.mergeObject(topology, deploymentTopology, "id");
        PaaSTopologyDeploymentContext deploymentContext = new PaaSTopologyDeploymentContext();
        deploymentContext.setPaaSTopology(topologyTreeBuilderService.buildPaaSTopology(topology));
        deploymentContext.setDeploymentTopology(deploymentTopology);
        alien4cloud.model.deployment.Deployment deployment = new alien4cloud.model.deployment.Deployment();
        deployment.setId(appName);
        deployment.setOrchestratorDeploymentId(appName);
        deploymentContext.setDeployment(deployment);
        Map<String, Location> locationMap = Maps.newHashMap();
        Location location = new Location();
        location.setInfrastructureType(locationName);
        locationMap.put(AlienConstants.GROUP_ALL, location);
        deploymentContext.setLocations(locationMap);

        deploymentTopology.setProviderDeploymentProperties(deploymentProperties);
        return deploymentContext;
    }

    public void launch(PaaSTopologyDeploymentContext deploymentContext) throws Exception {
        initializeCloudifyManagerConnection();
        final SettableFuture<Object> future = SettableFuture.create();
        cloudifyPaaSProvider.deploy(deploymentContext, new IPaaSCallback<Object>() {

            @Override
            public void onSuccess(Object data) {
                future.set(data);
            }

            @Override
            public void onFailure(Throwable throwable) {
                future.setException(throwable);
            }
        });
        future.get();
    }

    public String launch(String topologyName) throws Exception {
        return launch(topologyName, null);
    }

    public String launch(String topologyName, Map<String, String> deploymentProperties) throws Exception {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        String deploymentId = stackTraceElements[2].getMethodName();
        launch(buildPaaSDeploymentContext(deploymentId, topologyName, "amazon", deploymentProperties));
        return deploymentId;
    }

    public void verifyBlueprintUpload(String topology, String path) throws PluginConfigurationException {
        initializeCloudifyManagerConnection();
        // Check if cloudify accept the blueprint
        blueprintDAO.create(topology, path);
        blueprintDAO.delete(topology);
    }
}

{'fraction_non_alphanumeric': 0.0702726473175022, 'fraction_numerical': 0.0043975373790677225, 'mean_word_length': 4.298695246971109, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3873557', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2796, 'n_words': 533}