<commit_before>/*
 * Copyright 2015 Netflix, Inc.
 *
 * 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 com.netflix.spinnaker.orca.front50.tasks

import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.Task
import com.netflix.spinnaker.orca.TaskResult
import com.netflix.spinnaker.orca.front50.DependentPipelineStarter
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.model.Stage
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
@Slf4j
class StartPipelineTask implements Task {

  @Autowired(required = false)
  Front50Service front50Service

  @Autowired
  DependentPipelineStarter dependentPipelineStarter

  @Override
  TaskResult execute(Stage stage) {
    if (!front50Service) {
      throw new UnsupportedOperationException("Cannot start a stored pipeline, front50 is not enabled. Fix this by setting front50.enabled: true")
    }

    String application = stage.context.pipelineApplication ?: stage.context.application
    String pipelineId = stage.context.pipelineId ?: stage.context.pipeline
    Boolean isStrategy = stage.context.pipelineParameters?.strategy ?: false

    List<Map<String, Object>> pipelines = isStrategy ? front50Service.getStrategies(application) : front50Service.getPipelines(application, false)
    Map<String, Object> pipelineConfig = pipelines.find { it.id == pipelineId }

    if (!pipelineConfig) {
      throw new IllegalArgumentException("The referenced ${isStrategy ? 'custom strategy' : 'pipeline'} cannot be located (${pipelineId}")
    }

    if (pipelineConfig.getOrDefault("disabled", false)) {
      throw new IllegalArgumentException("The referenced ${isStrategy ? 'custom strategy' : 'pipeline'} is disabled")
    }

    def parameters = stage.context.pipelineParameters ?: [:]

    if (isStrategy) {
      def deploymentDetails = stage.context.deploymentDetails?.collect { Map it ->
        def base = [ami: it.ami, imageName: it.imageName, imageId: it.imageId]
        if (it.region) {
          base.region = it.region
        } else if (it.zone) {
          base.zone = it.zone
        }
        return base
      } ?: [:]

      if (deploymentDetails) {
        parameters.deploymentDetails = deploymentDetails
        if (!parameters.amiName && (parameters.region || parameters.zone)) {
          def details = deploymentDetails.find { (it.region && it.region == parameters.region) ||
                                                 (it.zone && it.zone == parameters.zone) }
          if (details) {
            parameters.amiName = details.ami
            parameters.imageId = details.imageId
          }
        }
      }
    }

    def pipeline = dependentPipelineStarter.trigger(pipelineConfig, stage.context.user, stage.execution, parameters, stage.id)

    new TaskResult(ExecutionStatus.SUCCEEDED, [executionId: pipeline.id, executionName: pipelineConfig.name])

  }

}
<commit_msg>fix(error msg): adding second ) (#2210)<commit_after>/*
 * Copyright 2015 Netflix, Inc.
 *
 * 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 com.netflix.spinnaker.orca.front50.tasks

import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.Task
import com.netflix.spinnaker.orca.TaskResult
import com.netflix.spinnaker.orca.front50.DependentPipelineStarter
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.model.Stage
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
@Slf4j
class StartPipelineTask implements Task {

  @Autowired(required = false)
  Front50Service front50Service

  @Autowired
  DependentPipelineStarter dependentPipelineStarter

  @Override
  TaskResult execute(Stage stage) {
    if (!front50Service) {
      throw new UnsupportedOperationException("Cannot start a stored pipeline, front50 is not enabled. Fix this by setting front50.enabled: true")
    }

    String application = stage.context.pipelineApplication ?: stage.context.application
    String pipelineId = stage.context.pipelineId ?: stage.context.pipeline
    Boolean isStrategy = stage.context.pipelineParameters?.strategy ?: false

    List<Map<String, Object>> pipelines = isStrategy ? front50Service.getStrategies(application) : front50Service.getPipelines(application, false)
    Map<String, Object> pipelineConfig = pipelines.find { it.id == pipelineId }

    if (!pipelineConfig) {
      throw new IllegalArgumentException("The referenced ${isStrategy ? 'custom strategy' : 'pipeline'} cannot be located (${pipelineId})")
    }

    if (pipelineConfig.getOrDefault("disabled", false)) {
      throw new IllegalArgumentException("The referenced ${isStrategy ? 'custom strategy' : 'pipeline'} is disabled")
    }

    def parameters = stage.context.pipelineParameters ?: [:]

    if (isStrategy) {
      def deploymentDetails = stage.context.deploymentDetails?.collect { Map it ->
        def base = [ami: it.ami, imageName: it.imageName, imageId: it.imageId]
        if (it.region) {
          base.region = it.region
        } else if (it.zone) {
          base.zone = it.zone
        }
        return base
      } ?: [:]

      if (deploymentDetails) {
        parameters.deploymentDetails = deploymentDetails
        if (!parameters.amiName && (parameters.region || parameters.zone)) {
          def details = deploymentDetails.find { (it.region && it.region == parameters.region) ||
                                                 (it.zone && it.zone == parameters.zone) }
          if (details) {
            parameters.amiName = details.ami
            parameters.imageId = details.imageId
          }
        }
      }
    }

    def pipeline = dependentPipelineStarter.trigger(pipelineConfig, stage.context.user, stage.execution, parameters, stage.id)

    new TaskResult(ExecutionStatus.SUCCEEDED, [executionId: pipeline.id, executionName: pipelineConfig.name])

  }

}

{'fraction_non_alphanumeric': 0.09616195698017714, 'fraction_numerical': 0.009559960635456208, 'mean_word_length': 3.4742138364779875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896032', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1910, 'n_words': 518}