<commit_before>// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

#include "csi/service_manager.hpp"

#include <algorithm>
#include <functional>
#include <list>
#include <utility>
#include <vector>

#include <mesos/http.hpp>

#include <mesos/agent/agent.hpp>

#include <process/after.hpp>
#include <process/collect.hpp>
#include <process/defer.hpp>
#include <process/dispatch.hpp>
#include <process/id.hpp>
#include <process/loop.hpp>
#include <process/process.hpp>
#include <process/timeout.hpp>

#include <stout/check.hpp>
#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/hashmap.hpp>
#include <stout/os.hpp>
#include <stout/result.hpp>
#include <stout/stringify.hpp>
#include <stout/strings.hpp>
#include <stout/try.hpp>

#include <stout/os/realpath.hpp>

#include "common/http.hpp"

#include "csi/paths.hpp"
#include "csi/v0_client.hpp"
#include "csi/v0_utils.hpp"

#include "internal/devolve.hpp"
#include "internal/evolve.hpp"

#include "slave/container_daemon.hpp"
#include "slave/state.hpp"

namespace http = process::http;
namespace slave = mesos::internal::slave;

using std::list;
using std::string;
using std::vector;

using process::Break;
using process::Continue;
using process::ControlFlow;
using process::Failure;
using process::Future;
using process::Owned;
using process::Process;
using process::ProcessBase;
using process::Promise;
using process::Timeout;

using process::grpc::StatusError;

using process::grpc::client::Runtime;

using slave::ContainerDaemon;

namespace mesos {
namespace csi {

// Timeout for a CSI plugin component to create its endpoint socket.
//
// TODO(chhsiao): Make the timeout configurable.
constexpr Duration CSI_ENDPOINT_CREATION_TIMEOUT = Minutes(1);


// Returns the container ID of the specified CSI plugin container. The container
// ID is of the following format:
//
//     <container_prefix><plugin_type>-<plugin_name>--<list_of_services>
//
// where <plugin_type> and <plugin_name> are the type and name of the CSI plugin
// with dots replaced by dashes, and <list_of_services> lists the CSI services
// provided by the component, concatenated with dashes.
static ContainerID getContainerId(
    const CSIPluginInfo& info,
    const string& containerPrefix,
    const CSIPluginContainerInfo& container)
{
  ContainerID containerId;
  containerId.set_value(
      containerPrefix +
      strings::join("-", strings::replace(info.type(), ".", "-"), info.name()) +
      "--" + strings::join("-", container.services()));

  return containerId;
}


class ServiceManagerProcess : public Process<ServiceManagerProcess>
{
public:
  ServiceManagerProcess(<commit_msg>Fixed a container ID generation issue in the CSI service manager.<commit_after>// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

#include "csi/service_manager.hpp"

#include <algorithm>
#include <functional>
#include <list>
#include <utility>
#include <vector>

#include <mesos/http.hpp>
#include <mesos/type_utils.hpp>

#include <mesos/agent/agent.hpp>

#include <process/after.hpp>
#include <process/collect.hpp>
#include <process/defer.hpp>
#include <process/dispatch.hpp>
#include <process/id.hpp>
#include <process/loop.hpp>
#include <process/process.hpp>
#include <process/timeout.hpp>

#include <stout/check.hpp>
#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/hashmap.hpp>
#include <stout/os.hpp>
#include <stout/result.hpp>
#include <stout/stringify.hpp>
#include <stout/strings.hpp>
#include <stout/try.hpp>

#include <stout/os/realpath.hpp>

#include "common/http.hpp"

#include "csi/paths.hpp"
#include "csi/v0_client.hpp"

#include "internal/devolve.hpp"
#include "internal/evolve.hpp"

#include "slave/container_daemon.hpp"
#include "slave/state.hpp"

namespace http = process::http;
namespace slave = mesos::internal::slave;

using std::list;
using std::string;
using std::vector;

using process::Break;
using process::Continue;
using process::ControlFlow;
using process::Failure;
using process::Future;
using process::Owned;
using process::Process;
using process::ProcessBase;
using process::Promise;
using process::Timeout;

using process::grpc::StatusError;

using process::grpc::client::Runtime;

using slave::ContainerDaemon;

namespace mesos {
namespace csi {

// Timeout for a CSI plugin component to create its endpoint socket.
//
// TODO(chhsiao): Make the timeout configurable.
constexpr Duration CSI_ENDPOINT_CREATION_TIMEOUT = Minutes(1);


// Returns the container ID of the specified CSI plugin container. The container
// ID is of the following format:
//
//     <container_prefix><plugin_type>-<plugin_name>--<list_of_services>
//
// where <plugin_type> and <plugin_name> are the type and name of the CSI plugin
// with dots replaced by dashes, and <list_of_services> lists the CSI services
// provided by the component, concatenated with dashes.
static ContainerID getContainerId(
    const CSIPluginInfo& info,
    const string& containerPrefix,
    const CSIPluginContainerInfo& container)
{
  // NOTE: We cannot simply stringify `container.services()` since it returns
  // `RepeatedField<int>`, so we reconstruct the list of services here.
  vector<Service> services;
  services.reserve(container.services_size());
  for (int i = 0; i < container.services_size(); i++) {
    services.push_back(container.services(i));
  }

  ContainerID containerId;
  containerId.set_value(
      containerPrefix +
      strings::join("-", strings::replace(info.type(), ".", "-"), info.name()) +
      "--" + strings::join("-", services));

  return containerId;
}


class ServiceManagerProcess : public Process<ServiceManagerProcess>
{
public:
  ServiceManagerProcess(
{'fraction_non_alphanumeric': 0.12019566736547868, 'fraction_numerical': 0.0019566736547868622, 'mean_word_length': 4.827361563517916, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 72, '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': '5257871', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2107, 'n_words': 683}