<commit_before>/*
 * Copyright (c) 2016 SnappyData, Inc. All rights reserved.
 *
 * 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. See accompanying
 * LICENSE file.
 */
package io.snappydata


import java.util.Properties

import scala.collection.JavaConversions._

import com.gemstone.gemfire.distributed.DistributedMember
import com.pivotal.gemfirexd.internal.engine.distributed.utils.GemFireXDUtils
import io.snappydata.impl.LeadImpl

import org.apache.spark.SparkContext
import org.apache.spark.sql.AnalysisException

object ToolsCallbackImpl extends ToolsCallback {

  override def invokeLeadStartAddonService(sc: SparkContext): Unit = {
    LeadImpl.invokeLeadStartAddonService(sc)
  }

  override def invokeStartFabricServer(sc: SparkContext,
      hostData: Boolean): Unit = {
    val properties = new Properties()
    sc.getConf.getOption(Property.locators).map { locator =>
      if (!Utils.LocatorURLPattern.matcher(locator).matches()) {
        throw new AnalysisException(s"locators property '$locator' should " +
            "be provided in the format host[port] or host:port", null)
      }
      properties.setProperty("locators", locator)
      sc.getConf.getOption(Property.mcastPort).map(
        properties.setProperty("mcast-port", _))
    }.getOrElse(properties.setProperty("mcast-port",
      sc.getConf.get(Property.mcastPort)))
    if (!hostData) {
      properties.setProperty("host-data", "false")
      // no DataDictionary persistence for non-embedded mode
      properties.setProperty("persist-dd", "false")
    }
    ServiceManager.getServerInstance.start(properties)
  }

  override def invokeStopFabricServer(sc: SparkContext): Unit = {
    ServiceManager.getServerInstance.stop(null)
  }

  def getAllLocators(sc: SparkContext): collection.Map[DistributedMember, String] = {
    val advisor = GemFireXDUtils.getGfxdAdvisor
    val locators = advisor.adviseLocators(null)
    val locatorServers = collection.mutable.HashMap[DistributedMember , String]()
    locators.foreach(locator => locatorServers.put(locator, advisor.getDRDAServers(locator)))<commit_msg>Handle all the store boot properties minor changes for scala code styling<commit_after>/*
 * Copyright (c) 2016 SnappyData, Inc. All rights reserved.
 *
 * 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. See accompanying
 * LICENSE file.
 */
package io.snappydata


import java.util.Properties

import scala.collection.JavaConverters._

import com.gemstone.gemfire.distributed.DistributedMember
import com.pivotal.gemfirexd.internal.engine.distributed.utils.GemFireXDUtils
import io.snappydata.impl.LeadImpl

import org.apache.spark.SparkContext
import org.apache.spark.sql.AnalysisException

object ToolsCallbackImpl extends ToolsCallback {

  override def invokeLeadStartAddonService(sc: SparkContext): Unit = {
    LeadImpl.invokeLeadStartAddonService(sc)
  }

  override def invokeStartFabricServer(sc: SparkContext,
      hostData: Boolean): Unit = {
    val properties = new Properties()
    sc.getConf.getAll.filter(
      p => p._1.startsWith(Constant.STORE_PROPERTY_PREFIX)).
        foreach(p => p._1 match {
          case Property.locators =>
            if (!Utils.LocatorURLPattern.matcher(p._2).matches()) {
              throw new AnalysisException(s"locators property " + p._2 + " should " +
                  "be provided in the format host[port] or host:port", null)
            }
            properties.setProperty("locators", p._2)

          case _ =>
            properties.setProperty(p._1.trim.replaceFirst(Constant.STORE_PROPERTY_PREFIX, ""), p._2)
        }
        )
    // overriding the host-data property based on the provided flag
    if (!hostData) {
      properties.setProperty("host-data", "false")
      // no DataDictionary persistence for non-embedded mode
      properties.setProperty("persist-dd", "false")
    }
    ServiceManager.getServerInstance.start(properties)
  }

  override def invokeStopFabricServer(sc: SparkContext): Unit = {
    ServiceManager.getServerInstance.stop(null)
  }

  def getAllLocators(sc: SparkContext): collection.Map[DistributedMember, String] = {
    val advisor = GemFireXDUtils.getGfxdAdvisor
    val locators = advisor.adviseLocators(null)
    val locatorServers = collection.mutable.HashMap[DistributedMember , String]()
    locators.asScala.foreach(locator =>
      locatorServers.put(locator, advisor.getDRDAServers(locator)))
{'fraction_non_alphanumeric': 0.09395848776871757, 'fraction_numerical': 0.004262416604892513, 'mean_word_length': 3.9423076923076925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4044258', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1492, 'n_words': 404}