Skip to content

Commit

Permalink
chore: simplify port config and amend cluster.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Oct 17, 2023
1 parent 7205320 commit 25d9605
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 43 deletions.
24 changes: 12 additions & 12 deletions cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# http://www.eclipse.org/legal/epl-2.0
#
# SPDX-License-Identifier: EPL-2.0

apiVersion: v1
kind: Namespace
metadata:
Expand Down Expand Up @@ -142,23 +143,23 @@ apiVersion: apps/v1
kind: Deployment
metadata:
namespace: jifa
name: master
name: jifa-master
labels:
app: master
app: jifa-master
spec:
replicas: 3
selector:
matchLabels:
app: master
app: jifa-master
template:
metadata:
labels:
app: master
app: jifa-master
spec:
serviceAccountName: jifa-service-account
containers:
- name: main-container
image: jifadocker/jifa-master
image: eclipsejifa/jifa:0.2.0-SNAPSHOT
imagePullPolicy: Always
volumeMounts:
- name: jifa-pv
Expand All @@ -172,11 +173,10 @@ spec:
value: root
- name: MYSQL_PASSWORD
value: password
command: ["java","-jar","/wd/jifa.jar"]
args: [ "--jifa.role=master", "--jifa.scheduling-strategy=elastic", "--jifa.storage-pvc-name=jifa-pvc", "--jifa.storage-path=/jifa-storage", "--jifa.worker-image=jifadocker/jifa-worker" ]
args: [ "--jifa.role=master", "--jifa.scheduling-strategy=elastic", "--jifa.storage-pvc-name=jifa-pvc", "--jifa.storage-path=/jifa-storage", "--jifa.worker-image=eclipsejifa/jifa:0.2.0-SNAPSHOT" ]
ports:
- name: jifa-http-port
containerPort: 9102
- name: jifa-service-port
containerPort: 8102
volumes:
- name: jifa-pv
persistentVolumeClaim:
Expand All @@ -187,12 +187,12 @@ apiVersion: v1
kind: Service
metadata:
namespace: jifa
name: master-service
name: jifa-service
spec:
selector:
app: master
app: jifa-master
ports:
- protocol: TCP
port: 80
targetPort: jifa-http-port
targetPort: jifa-service-port
type: LoadBalancer
2 changes: 1 addition & 1 deletion server/server.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ tasks.register('runStaticWorker', BootRun) {
classpath(project.sourceSets.main.runtimeClasspath)
mainClass.convention(mainClassName)

args('--jifa.role=static-worker')
args('--jifa.role=static-worker', '--jifa.port=9102')
setJvmOptionsAndDevKeys(it)
setMysqlEnv(it)
}
Expand Down
24 changes: 10 additions & 14 deletions server/src/main/java/org/eclipse/jifa/server/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

import static org.eclipse.jifa.server.Constant.DEFAULT_WORKER_PORT;
import static org.eclipse.jifa.server.Constant.DEFAULT_PORT;

@ConfigurationProperties(prefix = "jifa", ignoreUnknownFields = false)
@Validated
Expand All @@ -55,28 +55,31 @@ public class Configuration {
*
* @see #init()
*/
@PositiveOrZero
private int port = 0;
@Positive
private int port = DEFAULT_PORT;

/**
* The storage path.
*/
private Path storagePath;

/**
* The scheduling strategy.
*/
private SchedulingStrategy schedulingStrategy;

/**
* The name of PersistentVolumeClaim. Used by master to schedule an elastic worker
* The name of PersistentVolumeClaim.
*/
private String storagePVCName;

/**
* The container image of worker. Used by master to schedule an elastic worker
* The container image of worker.
*/
private String workerImage;

@PositiveOrZero
private int elasticWorkerPort;
@Positive
private int elasticWorkerPort = DEFAULT_PORT;

/**
* Idle threshold in minutes of an elastic worker
Expand Down Expand Up @@ -130,9 +133,6 @@ private void init() {
"jifa.storage-pvc-name must be set and not blank when role is master and scheduling strategy is elastic");
Validate.notBlank(workerImage,
"jifa.worker-image name must be set and not blank when role is master and scheduling strategy is elastic");
if (elasticWorkerPort == 0) {
elasticWorkerPort = DEFAULT_WORKER_PORT;
}
}
}

Expand All @@ -146,10 +146,6 @@ private void init() {
}
}

if (port == 0) {
port = role == Role.MASTER ? Constant.DEFAULT_MASTER_PORT : DEFAULT_WORKER_PORT;
}

if (publicKey == null || privateKey == null) {
publicKey = DefaultRSAKeyPair.getPublicKey();
privateKey = DefaultRSAKeyPair.getPrivateKey();
Expand Down
6 changes: 2 additions & 4 deletions server/src/main/java/org/eclipse/jifa/server/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

public interface Constant extends org.eclipse.jifa.common.Constant {

int DEFAULT_MASTER_PORT = 9102;

int DEFAULT_WORKER_PORT = 8102;
int DEFAULT_PORT = 8102;

String COOKIE_JIFA_TOKEN_KEY = "jifa-token";

Expand Down Expand Up @@ -75,7 +73,7 @@ public interface Constant extends org.eclipse.jifa.common.Constant {

String K8S_NAMESPACE = "jifa";

String POD_NAME_PREFIX = "elastic-worker-";
String POD_NAME_PREFIX = "jifa-elastic-worker-";

String ELASTIC_WORKER_IDENTITY_ENV_KEY = "JIFA_ELASTIC_WORKER_IDENTITY";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.util.Map;
import java.util.function.BiConsumer;

import static org.eclipse.jifa.server.Constant.DEFAULT_WORKER_PORT;
import static org.eclipse.jifa.server.Constant.DEFAULT_PORT;
import static org.eclipse.jifa.server.Constant.ELASTIC_WORKER_IDENTITY_ENV_KEY;
import static org.eclipse.jifa.server.Constant.HTTP_API_PREFIX;
import static org.eclipse.jifa.server.Constant.HTTP_HEALTH_CHECK_MAPPING;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin

V1Probe healthCheck = new V1Probe();
healthCheck.httpGet(new V1HTTPGetAction().path(HTTP_API_PREFIX + HTTP_HEALTH_CHECK_MAPPING)
.port(new IntOrString(DEFAULT_WORKER_PORT)))
.port(new IntOrString(DEFAULT_PORT)))
.initialDelaySeconds(5)
.periodSeconds(2)
.failureThreshold(30);
Expand All @@ -107,10 +107,9 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin
.addEnvItem(new V1EnvVar().name("MYSQL_USERNAME").value(System.getenv("MYSQL_USERNAME")))
.addEnvItem(new V1EnvVar().name("MYSQL_PASSWORD").value(System.getenv("MYSQL_PASSWORD")))
.addEnvItem(new V1EnvVar().name(ELASTIC_WORKER_IDENTITY_ENV_KEY).value(Long.toString(identity)))
.command(List.of("java","-jar","/wd/jifa.jar"))
.args(List.of("--jifa.role=elastic-worker",
"--jifa.storage-path=" + config.getStoragePath().toString()))
.addPortsItem(new V1ContainerPort().containerPort(DEFAULT_WORKER_PORT))
.addPortsItem(new V1ContainerPort().containerPort(DEFAULT_PORT))
.resources(resourceRequirements)
.startupProbe(healthCheck);

Expand All @@ -133,12 +132,14 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin
outerLoop:
while (true) {
V1PodStatus status = pod.getStatus();
List<V1ContainerStatus> containerStatuses = status.getContainerStatuses();
if (containerStatuses != null) {
for (V1ContainerStatus containerStatus : containerStatuses) {
if (WORKER_CONTAINER_NAME.equals(containerStatus.getName())) {
if (containerStatus.getReady()) {
break outerLoop;
if (status != null) {
List<V1ContainerStatus> containerStatuses = status.getContainerStatuses();
if (containerStatuses != null) {
for (V1ContainerStatus containerStatus : containerStatuses) {
if (WORKER_CONTAINER_NAME.equals(containerStatus.getName())) {
if (containerStatus.getReady()) {
break outerLoop;
}
}
}
}
Expand Down Expand Up @@ -170,8 +171,11 @@ public void terminateInconsistentInstancesQuietly() {
V1PodList pods = api.listNamespacedPod(K8S_NAMESPACE, null, null, null, null, null, null, null, null, null, null);
for (V1Pod pod : pods.getItems()) {
try {
if (pod.getMetadata() == null) {
continue;
}
String name = pod.getMetadata().getName();
if (!name.startsWith(POD_NAME_PREFIX)) {
if (name == null || !name.startsWith(POD_NAME_PREFIX)) {
continue;
}
long identity = Long.parseLong(name.substring(POD_NAME_PREFIX.length()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void before() {
@Test
public void test() throws Exception {
StompSession session = webSocketStompClient
.connectAsync(String.format("ws://localhost:%d/%s", Constant.DEFAULT_WORKER_PORT, Constant.STOMP_ENDPOINT), new StompSessionHandlerAdapter() {
.connectAsync(String.format("ws://localhost:%d/%s", Constant.DEFAULT_PORT, Constant.STOMP_ENDPOINT), new StompSessionHandlerAdapter() {
})
.get(1000, TimeUnit.SECONDS);

Expand Down

0 comments on commit 25d9605

Please sign in to comment.