Skip to content

Commit 812066a

Browse files
authored
Merge pull request #567 from Pyro2266/clustering-app
Clustering improvements and example application
2 parents 6dcc410 + b652a45 commit 812066a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3084
-14
lines changed

docs/ODL-migration-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# How-To migrate from ODL to lighty.io
2-
This guide describes migration procedure of SDN application from [OpenDaylight](https://www.opendaylight.org/)/[Karaf](https://karaf.apache.org/) to [lighty.io](https://github.com/PantheonTechnologies/lighty-core).
2+
This guide describes migration procedure of SDN application from [OpenDaylight](https://www.opendaylight.org/)/[Karaf](https://karaf.apache.org/) to [lighty.io](https://github.com/PANTHEONtech/lighty-core).
33
It contains summary of practical experiences based on real-life ODL project migrations.
44

55
### 1. ODL application review

lighty-core/dependency-versions/pom.xml

+37-6
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,25 @@
106106
<artifactId>guice</artifactId>
107107
<version>4.2.2</version>
108108
</dependency>
109-
<dependency>
110-
<groupId>org.testng</groupId>
111-
<artifactId>testng</artifactId>
112-
<version>6.14.3</version>
113-
<scope>test</scope>
114-
</dependency>
115109
<dependency>
116110
<groupId>com.beust</groupId>
117111
<artifactId>jcommander</artifactId>
118112
<version>1.78</version>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.apache.httpcomponents</groupId>
116+
<artifactId>httpclient</artifactId>
117+
<version>4.5.13</version>
118+
</dependency>
119+
<dependency>
120+
<groupId>io.fabric8</groupId>
121+
<artifactId>kubernetes-client</artifactId>
122+
<version>4.6.0</version>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.testng</groupId>
126+
<artifactId>testng</artifactId>
127+
<version>6.14.3</version>
119128
<scope>test</scope>
120129
</dependency>
121130

@@ -150,6 +159,28 @@
150159
<artifactId>javax.ws.rs-api</artifactId>
151160
<version>2.1.1</version>
152161
</dependency>
162+
163+
<!--akka management and bootstrap-->
164+
<dependency>
165+
<groupId>com.lightbend.akka.discovery</groupId>
166+
<artifactId>akka-discovery-kubernetes-api_2.12</artifactId>
167+
<version>1.0.1</version>
168+
</dependency>
169+
<dependency>
170+
<groupId>com.lightbend.akka.management</groupId>
171+
<artifactId>akka-management_2.12</artifactId>
172+
<version>1.0.1</version>
173+
</dependency>
174+
<dependency>
175+
<groupId>com.lightbend.akka.management</groupId>
176+
<artifactId>akka-management-cluster-http_2.12</artifactId>
177+
<version>1.0.1</version>
178+
</dependency>
179+
<dependency>
180+
<groupId>com.lightbend.akka.management</groupId>
181+
<artifactId>akka-management-cluster-bootstrap_2.12</artifactId>
182+
<version>1.0.1</version>
183+
</dependency>
153184
</dependencies>
154185
</dependencyManagement>
155186

lighty-core/lighty-bom/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
<artifactId>lighty-controller</artifactId>
3939
<version>12.2.1-SNAPSHOT</version>
4040
</dependency>
41+
<dependency>
42+
<groupId>io.lighty.core</groupId>
43+
<artifactId>lighty-clustering</artifactId>
44+
<version>12.2.1-SNAPSHOT</version>
45+
</dependency>
4146

4247
<!-- DI framework integrations -->
4348
<dependency>

lighty-core/lighty-clustering/pom.xml

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2020 Pantheon Technologies s.r.o. All Rights Reserved.
4+
5+
This program and the accompanying materials are made available under the
6+
terms of the Eclipse Public License v1.0 which accompanies this distribution,
7+
and is available at https://www.eclipse.org/legal/epl-v10.html
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<parent>
13+
<groupId>io.lighty.core</groupId>
14+
<artifactId>lighty-parent</artifactId>
15+
<version>12.2.1-SNAPSHOT</version>
16+
<relativePath>../lighty-parent</relativePath>
17+
</parent>
18+
19+
<artifactId>lighty-clustering</artifactId>
20+
21+
<name>${project.groupId}:${project.artifactId}</name>
22+
<url>https://github.com/PANTHEONtech/lighty-core</url>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-api</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.slf4j</groupId>
31+
<artifactId>slf4j-log4j12</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>commons-io</groupId>
35+
<artifactId>commons-io</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.json</groupId>
39+
<artifactId>json</artifactId>
40+
<version>20131018</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.fabric8</groupId>
44+
<artifactId>kubernetes-client</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.github.spotbugs</groupId>
48+
<artifactId>spotbugs-annotations</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.google.guava</groupId>
52+
<artifactId>guava</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.apache.httpcomponents</groupId>
56+
<artifactId>httpclient</artifactId>
57+
</dependency>
58+
59+
<!--ODL dependencies-->
60+
<dependency>
61+
<groupId>org.opendaylight.mdsal</groupId>
62+
<artifactId>mdsal-binding-api</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.opendaylight.mdsal</groupId>
66+
<artifactId>yang-binding</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.opendaylight.controller</groupId>
70+
<artifactId>sal-cluster-admin-api</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.opendaylight.controller</groupId>
74+
<artifactId>sal-distributed-datastore</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.opendaylight.mdsal</groupId>
78+
<artifactId>mdsal-singleton-common-api</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.opendaylight.controller</groupId>
82+
<artifactId>sal-distributed-eos</artifactId>
83+
</dependency>
84+
85+
<!--akka management and bootstrap-->
86+
<dependency>
87+
<groupId>com.lightbend.akka.discovery</groupId>
88+
<artifactId>akka-discovery-kubernetes-api_2.12</artifactId>
89+
</dependency>
90+
<dependency>
91+
<groupId>com.lightbend.akka.management</groupId>
92+
<artifactId>akka-management_2.12</artifactId>
93+
</dependency>
94+
<dependency>
95+
<groupId>com.lightbend.akka.management</groupId>
96+
<artifactId>akka-management-cluster-http_2.12</artifactId>
97+
</dependency>
98+
<dependency>
99+
<groupId>com.lightbend.akka.management</groupId>
100+
<artifactId>akka-management-cluster-bootstrap_2.12</artifactId>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>com.typesafe.akka</groupId>
105+
<artifactId>akka-actor_2.12</artifactId>
106+
</dependency>
107+
</dependencies>
108+
109+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 PANTHEON.tech s.r.o. All Rights Reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v10.html
7+
*/
8+
package io.lighty.core.cluster;
9+
10+
import java.util.Optional;
11+
import org.eclipse.jdt.annotation.NonNull;
12+
import org.opendaylight.mdsal.binding.api.DataBroker;
13+
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
14+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService;
15+
16+
public interface ClusteringHandler {
17+
18+
void initClustering();
19+
20+
void start(@NonNull ClusterSingletonServiceProvider clusterSingletonServiceProvider,
21+
@NonNull ClusterAdminService clusterAdminRPCService, @NonNull DataBroker bindingDataBroker);
22+
23+
Optional<String> getModuleConfig();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2020 PANTHEON.tech s.r.o. All Rights Reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v10.html
7+
*/
8+
package io.lighty.core.cluster;
9+
10+
import com.typesafe.config.Config;
11+
import io.lighty.core.cluster.kubernetes.KubernetesClusteringHandlerImpl;
12+
import java.util.Optional;
13+
import org.eclipse.jdt.annotation.NonNull;
14+
import org.opendaylight.controller.cluster.ActorSystemProvider;
15+
16+
public final class ClusteringHandlerProvider {
17+
18+
private ClusteringHandlerProvider() {
19+
// should not be instantiated
20+
}
21+
22+
public static Optional<ClusteringHandler> getClusteringHandler(@NonNull ActorSystemProvider actorSystemProvider,
23+
@NonNull Config akkaDeploymentConfig) {
24+
if (akkaDeploymentConfig.hasPath("akka.discovery.method")) {
25+
String clusteringTool = akkaDeploymentConfig.getString("akka.discovery.method");
26+
if ("kubernetes-api".equals(clusteringTool)) {
27+
return Optional.of(new KubernetesClusteringHandlerImpl(actorSystemProvider, akkaDeploymentConfig));
28+
}
29+
}
30+
return Optional.empty();
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2020 PANTHEON.tech s.r.o. All Rights Reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v10.html
7+
*/
8+
package io.lighty.core.cluster.config;
9+
10+
import com.typesafe.config.Config;
11+
import com.typesafe.config.ConfigFactory;
12+
import java.util.List;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
public final class ClusteringConfigUtils {
17+
18+
private static final Logger LOG = LoggerFactory.getLogger(ClusteringConfigUtils.class);
19+
20+
public static final String MODULE_SHARDS_TMP_PATH = "/tmp/module-shards.conf";
21+
public static final String K8S_POD_RESTART_TIMEOUT_PATH = "akka.lighty-kubernetes.pod-restart-timeout";
22+
23+
private ClusteringConfigUtils() {
24+
// this class should not be instantiated
25+
}
26+
27+
/**
28+
* Generate content of a Module-Shards.conf that specifies the members on which the Shards should be replicated.
29+
* @param memberRoles - roles (members) to which the module shards should be replicated to
30+
*/
31+
public static String generateModuleShardsForMembers(List<String> memberRoles) {
32+
return String.format("module-shards = [%n%s]", String.join(",\n",
33+
new String[]{generateShard("default", memberRoles),
34+
generateShard("topology", memberRoles),
35+
generateShard("inventory", memberRoles)
36+
}));
37+
}
38+
39+
public static boolean isKubernetesDeployment(Config actorSystemConfig) {
40+
return actorSystemConfig.hasPath("akka.discovery.method")
41+
&& actorSystemConfig.getString("akka.discovery.method").equalsIgnoreCase("kubernetes-api");
42+
}
43+
44+
private static String generateShard(String name, List<String> replicas) {
45+
return " {"
46+
+ " name = \"" + name + "\"\n"
47+
+ " shards = [\n"
48+
+ " {\n"
49+
+ " name=\"" + name + "\"\n"
50+
+ " replicas = " + replicas
51+
+ " \n"
52+
+ " }\n"
53+
+ " ]\n"
54+
+ " }";
55+
}
56+
57+
/**
58+
* Prepared for future when Module Shards Config could be created and loaded dynamically in runtime
59+
* instead of creating File and then passing it's path.
60+
*
61+
* @param memberRoles - roles (members) to which the module shards should be replicated to
62+
* @return Config object representing this Module-Shards configuration
63+
*/
64+
public static Config getModuleShardsConfigForMember(List<String> memberRoles) {
65+
LOG.info("Generating Module-Shards CONFIG");
66+
return ConfigFactory.parseString(generateModuleShardsForMembers(memberRoles));
67+
}
68+
}

0 commit comments

Comments
 (0)