<commit_before>/*
Copyright 2017 The Kubernetes Authors.

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 server

import (
	"fmt"
	"net/http"

	"github.com/kubernetes-incubator/service-catalog/pkg/api"
	genericapiserverstorage "k8s.io/apiserver/pkg/server/storage"
	"k8s.io/apiserver/pkg/storage/etcd3/preflight"

	"github.com/golang/glog"
	"github.com/kubernetes-incubator/service-catalog/pkg/apiserver"
	"github.com/kubernetes-incubator/service-catalog/pkg/apiserver/options"
	"github.com/kubernetes-incubator/service-catalog/pkg/registry/servicecatalog/server"
)

// RunServer runs an API server with configuration according to opts
func RunServer(opts *ServiceCatalogServerOptions, stopCh <-chan struct{}) error {
	storageType, err := opts.StorageType()
	if err != nil {
		return err
	}
	if stopCh == nil {
		/* the caller of RunServer should generate the stop channel
		if there is a need to stop the API server */
		stopCh = make(chan struct{})
	}

	err = opts.Validate()
	if nil != err {
		return err
	}

	if storageType == server.StorageTypeEtcd {
		return runEtcdServer(opts, stopCh)
	}
	// This should never happen, catch for potential bugs
	panic("Unexpected storage type: " + storageType)
}

func runEtcdServer(opts *ServiceCatalogServerOptions, stopCh <-chan struct{}) error {
	etcdOpts := opts.EtcdOptions
	glog.V(4).Infoln("Preparing to run API server")
	genericConfig, scConfig, err := buildGenericConfig(opts)
	if err != nil {
		return err
	}

	glog.V(4).Infoln("Creating storage factory")

	// The API server stores objects using a particular API version for each
	// group, regardless of API version of the object when it was created.
	//
	// storageGroupsToEncodingVersion holds a map of API group to version that<commit_msg>Rename the imported package to avoid name conflict (#1603)<commit_after>/*
Copyright 2017 The Kubernetes Authors.

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 server

import (
	"fmt"
	"net/http"

	"github.com/kubernetes-incubator/service-catalog/pkg/api"
	genericapiserverstorage "k8s.io/apiserver/pkg/server/storage"
	"k8s.io/apiserver/pkg/storage/etcd3/preflight"

	"github.com/golang/glog"
	"github.com/kubernetes-incubator/service-catalog/pkg/apiserver"
	"github.com/kubernetes-incubator/service-catalog/pkg/apiserver/options"
	registryserver "github.com/kubernetes-incubator/service-catalog/pkg/registry/servicecatalog/server"
)

// RunServer runs an API server with configuration according to opts
func RunServer(opts *ServiceCatalogServerOptions, stopCh <-chan struct{}) error {
	storageType, err := opts.StorageType()
	if err != nil {
		return err
	}
	if stopCh == nil {
		/* the caller of RunServer should generate the stop channel
		if there is a need to stop the API server */
		stopCh = make(chan struct{})
	}

	err = opts.Validate()
	if nil != err {
		return err
	}

	if storageType == registryserver.StorageTypeEtcd {
		return runEtcdServer(opts, stopCh)
	}
	// This should never happen, catch for potential bugs
	panic("Unexpected storage type: " + storageType)
}

func runEtcdServer(opts *ServiceCatalogServerOptions, stopCh <-chan struct{}) error {
	etcdOpts := opts.EtcdOptions
	glog.V(4).Infoln("Preparing to run API server")
	genericConfig, scConfig, err := buildGenericConfig(opts)
	if err != nil {
		return err
	}

	glog.V(4).Infoln("Creating storage factory")

	// The API server stores objects using a particular API version for each
	// group, regardless of API version of the object when it was created.
	//
	// storageGroupsToEncodingVersion holds a map of API group to version that
{'fraction_non_alphanumeric': 0.09153065725628584, 'fraction_numerical': 0.0066166740185266875, 'mean_word_length': 4.398809523809524, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2541771', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1330, 'n_words': 472}