<commit_before>/*
 * Copyright (C) FuseSource, Inc.
 *   http://fusesource.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.fusesource.fabric.openshift;

import com.openshift.client.ApplicationScale;
import com.openshift.client.IApplication;
import com.openshift.client.IDomain;
import com.openshift.client.IHttpClient;
import com.openshift.client.IOpenShiftConnection;
import com.openshift.client.IUser;
import com.openshift.client.OpenShiftConnectionFactory;
import com.openshift.internal.client.GearProfile;
import com.openshift.internal.client.StandaloneCartridge;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.fusesource.fabric.api.Container;
import org.fusesource.fabric.api.ContainerProvider;
import org.fusesource.fabric.api.FabricService;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


@Component(name = "org.fusesource.fabric.container.provider.openshift",
        description = "Fabric Openshift Container Provider",
        immediate = true)
@Service(ContainerProvider.class)
public class OpenshiftContainerProvider implements ContainerProvider<CreateOpenshiftContainerOptions, CreateOpenshiftContainerMetadata> {

    private static final String SCHEME = "openshift";

    private static final String REGISTRY_CART = "https://raw.github.com/jboss-fuse/fuse-registry-openshift-cartridge/master/metadata/manifest.yml";
    private static final String PLAIN_CART = "https://raw.github.com/jboss-fuse/fuse-openshift-cartridge/master/metadata/manifest.yml";

    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
    private IOpenShiftConnection connection;

    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
    private FabricService fabricService;

    @Override
    public Set<CreateOpenshiftContainerMetadata> create(CreateOpenshiftContainerOptions options) throws Exception {
        Set<CreateOpenshiftContainerMetadata> metadata = new HashSet<CreateOpenshiftContainerMetadata>();
        IUser user = getOrCreateConnection(options).getUser();
        IDomain domain =  getOrCreateDomain(user, options);
        int number = Math.max(options.getNumber(), 1);
        StandaloneCartridge cartridge = options.isEnsembleServer() ? new StandaloneCartridge(REGISTRY_CART) : new StandaloneCartridge(PLAIN_CART);

        String zookeeperUrl = fabricService.getZookeeperUrl();
        String zookeeperPassword = fabricService.getZookeeperPassword();

        Map<String,String> userEnvVars = new HashMap<String, String>();
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);

        String initGitUrl = null;
        int timeout = IHttpClient.NO_TIMEOUT;
        ApplicationScale scale = null;

        for (int i = 1; i <= number; i++) {
            IApplication application = domain.createApplication(options.getName(),cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
            String containerName = application.getName() + "-" + application.getUUID();
            if (!options.isEnsembleServer()) {
                application.restart();
            }
            CreateOpenshiftContainerMetadata meta = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getCreationLog());
            meta.setContainerName(containerName);
            meta.setCreateOptions(options);
            metadata.add(meta);
        }
        return metadata;
    }

    @Override
    public void start(Container container) {
        getContainerApplication(container).start();
    }<commit_msg>avoid container restarts which we don't need any more since we pass in all the right details<commit_after>/*
 * Copyright (C) FuseSource, Inc.
 *   http://fusesource.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.fusesource.fabric.openshift;

import com.openshift.client.ApplicationScale;
import com.openshift.client.IApplication;
import com.openshift.client.IDomain;
import com.openshift.client.IHttpClient;
import com.openshift.client.IOpenShiftConnection;
import com.openshift.client.IUser;
import com.openshift.client.OpenShiftConnectionFactory;
import com.openshift.internal.client.GearProfile;
import com.openshift.internal.client.StandaloneCartridge;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.fusesource.fabric.api.Container;
import org.fusesource.fabric.api.ContainerProvider;
import org.fusesource.fabric.api.FabricService;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


@Component(name = "org.fusesource.fabric.container.provider.openshift",
        description = "Fabric Openshift Container Provider",
        immediate = true)
@Service(ContainerProvider.class)
public class OpenshiftContainerProvider implements ContainerProvider<CreateOpenshiftContainerOptions, CreateOpenshiftContainerMetadata> {

    private static final String SCHEME = "openshift";

    private static final String REGISTRY_CART = "https://raw.github.com/jboss-fuse/fuse-registry-openshift-cartridge/master/metadata/manifest.yml";
    private static final String PLAIN_CART = "https://raw.github.com/jboss-fuse/fuse-openshift-cartridge/master/metadata/manifest.yml";

    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
    private IOpenShiftConnection connection;

    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
    private FabricService fabricService;

    @Override
    public Set<CreateOpenshiftContainerMetadata> create(CreateOpenshiftContainerOptions options) throws Exception {
        Set<CreateOpenshiftContainerMetadata> metadata = new HashSet<CreateOpenshiftContainerMetadata>();
        IUser user = getOrCreateConnection(options).getUser();
        IDomain domain =  getOrCreateDomain(user, options);
        int number = Math.max(options.getNumber(), 1);
        StandaloneCartridge cartridge = options.isEnsembleServer() ? new StandaloneCartridge(REGISTRY_CART) : new StandaloneCartridge(PLAIN_CART);

        String zookeeperUrl = fabricService.getZookeeperUrl();
        String zookeeperPassword = fabricService.getZookeeperPassword();

        Map<String,String> userEnvVars = new HashMap<String, String>();
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
        userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);

        String initGitUrl = null;
        int timeout = IHttpClient.NO_TIMEOUT;
        ApplicationScale scale = null;

        for (int i = 1; i <= number; i++) {
            IApplication application = domain.createApplication(options.getName(),cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
            String containerName = application.getName() + "-" + application.getUUID();
/*
            // now we pass in the environemnt variables we don't need to restart
            if (!options.isEnsembleServer()) {
                application.restart();
            }
*/
            CreateOpenshiftContainerMetadata meta = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getCreationLog());
            meta.setContainerName(containerName);
            meta.setCreateOptions(options);
            metadata.add(meta);
        }
        return metadata;
    }

    @Override
    public void start(Container container) {
        getContainerApplication(container).start();
    }
{'fraction_non_alphanumeric': 0.09201077199281867, 'fraction_numerical': 0.0013464991023339318, 'mean_word_length': 4.200116686114352, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '1571516', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2416, 'n_words': 554}