Skip to content
Snippets Groups Projects
Commit 8c081590 authored by Jesper Fyhr Knudsen's avatar Jesper Fyhr Knudsen
Browse files

Handle situation where Chaos is unavailable

parent 23406442
Branches
No related tags found
No related merge requests found
......@@ -74,11 +74,9 @@ public class AuthenticatedChaosClient implements HeartbeatGateway{
PortalResponse response = gateway.call("POST", "v6/Job/Set", "sessionGUID=" + sessionId + "&data=" + data);
}
@Override
public void set(ClusterState heartbeat) {
try {
String json = gson.toJson(heartbeat);
System.out.println(json);
PortalResponse response = gateway.call("POST", "v6/Heartbeat/Set", "sessionGUID=" + sessionId + "&state=" + json);
if("Chaos.Portal.Core.Exceptions.InsufficientPermissionsException".equals(response.Error.Fullname))
......
......@@ -14,12 +14,9 @@ public class ResponseTest {
String json = new Gson().toJson(res1);
System.out.println(json);
Type type = new TypeToken<Response<MyResult>>() {
}.getType();
System.out.println(type);
Response<MyResult> res11 = new Gson().fromJson(json, type);
for (MyResult result : res11.Results) {
......
......@@ -34,6 +34,32 @@ public class ConcurrentJobQueue {
return result;
}
public Job pop() {
Job job;
synchronized (_hashJobs.values()) {
job = peek();
if(job != null)
_hashJobs.remove(job.id);
}
return job;
}
public Job peek() {
Job job = null;
synchronized (_hashJobs.values()) {
for (Job job1: _hashJobs.values()) {
job = job1;
break;
}
}
return job;
}
public boolean contains(String id) {
return _hashJobs.containsKey(id);
}
......
......@@ -37,8 +37,13 @@ public class Synchronization extends TimerTask {
}
public void synchronize() {
for (SynchronizationTask task : tasks)
for (SynchronizationTask task : tasks) {
try {
task.action();
} catch (Exception e) {
System.err.println("Synchronization (" + task.getClass().getName()+ ") - " + e.getMessage());
}
}
}
public void stop() {
......
......@@ -4,6 +4,7 @@
*/
package com.chaos.octopus.server.synchronization;
import com.chaos.octopus.commons.core.Job;
import com.chaos.octopus.server.ConcurrentJobQueue;
import com.chaos.sdk.AuthenticatedChaosClient;
......@@ -18,12 +19,13 @@ public class UpdateJob implements SynchronizationTask {
this.client = client;
}
@Override
public void action() {
for (Job job: this.jobs.popAll()) {
try {
client.jobSet(jobs.popAll());
client.jobSet(job);
} catch (IOException e){
e.printStackTrace();
this.jobs.put(job);
}
}
}
}
......@@ -23,7 +23,7 @@ public class UpdateJobTest
updateJob.action();
verify(chaos).jobSet(any(List.class));
verify(chaos).jobSet(any(Job.class));
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment