blob: 3924cd77cea3949eb5698272e90c09d7b462b1f1 [file] [log] [blame]
Jordan Halterman07f052b2017-10-08 14:22:41 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.primitives.impl;
17
18import java.io.File;
19import java.nio.charset.StandardCharsets;
20import java.util.concurrent.CompletableFuture;
21
22import com.google.common.hash.Hashing;
23import io.atomix.protocols.raft.cluster.MemberId;
24import org.onosproject.cluster.ClusterService;
25import org.onosproject.cluster.Partition;
26import org.onosproject.core.Version;
27import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
28
29/**
30 * Storage partition inactive on the local node.
31 */
32public class InactiveStoragePartition extends StoragePartition {
33 static final String INACTIVE_DIR = PARTITIONS_DIR + "archive/";
34
35 public InactiveStoragePartition(
36 Partition partition,
37 ClusterCommunicationService clusterCommunicator,
38 ClusterService clusterService) {
39 super(partition, clusterCommunicator, clusterService);
40 }
41
42 @Override
43 public String getName() {
44 Version version = partition.getVersion();
45 if (version != null) {
46 long hashCode = Hashing.sha256().hashString(version.toString(), StandardCharsets.UTF_8).asLong();
47 return String.format("%s-%d", partition.getId(), hashCode);
48 }
49 return partition.getId().toString();
50 }
51
52 @Override
53 public File getDataFolder() {
54 return new File(INACTIVE_DIR + partition.getId());
55 }
56
57 @Override
58 protected CompletableFuture<Void> openServer() {
59 StoragePartitionServer server = new StoragePartitionServer(
60 this,
61 MemberId.from(localNodeId.id()),
62 clusterCommunicator);
63 return server.open().thenRun(() -> this.server = server);
64 }
65}