From 49bb0eb9c4a9238743ab09e516c7f223db871836 Mon Sep 17 00:00:00 2001 From: dougsleite Date: Tue, 19 May 2009 19:53:33 +0000 Subject: git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776434 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/dougsleite/guardian-model/.classpath | 8 + sandbox/dougsleite/guardian-model/.project | 23 ++ sandbox/dougsleite/guardian-model/pom.xml | 100 ++++++++ .../tuscany/sca/guardian/BlockingInterface.java | 30 +++ .../org/apache/tuscany/sca/guardian/Context.java | 74 ++++++ .../tuscany/sca/guardian/GlobalException.java | 87 +++++++ .../apache/tuscany/sca/guardian/GuardianGroup.java | 26 ++ .../tuscany/sca/guardian/GuardianGroupImpl.java | 180 +++++++++++++ .../tuscany/sca/guardian/GuardianMember.java | 36 +++ .../tuscany/sca/guardian/GuardianMemberImpl.java | 209 ++++++++++++++++ .../tuscany/sca/guardian/GuardianPrimitives.java | 37 +++ .../apache/tuscany/sca/guardian/JoinException.java | 39 +++ .../tuscany/sca/guardian/LeaveException.java | 38 +++ .../tuscany/sca/guardian/SuspendException.java | 38 +++ .../tuscany/sca/guardian/UnhandledException.java | 38 +++ .../guardian/exceptions/BackupFailedException.java | 24 ++ .../guardian/exceptions/BackupJoinedException.java | 24 ++ .../exceptions/PrimaryExistsException.java | 24 ++ .../exceptions/PrimaryFailedException.java | 24 ++ .../src/main/resources/server-backup.composite | 51 ++++ .../itests/ApplyUpdateFailureException.java | 22 ++ .../sca/guardian/itests/GuardianLaunch.java | 31 +++ .../apache/tuscany/sca/guardian/itests/Launch.java | 50 ++++ .../tuscany/sca/guardian/itests/Launch2.java | 50 ++++ .../apache/tuscany/sca/guardian/itests/Node.java | 34 +++ .../tuscany/sca/guardian/itests/NodeImpl.java | 277 +++++++++++++++++++++ .../sca/guardian/itests/Participant1Launch.java | 45 ++++ .../sca/guardian/itests/Participant2Launch.java | 45 ++++ .../itests/PrimaryServiceFailureException.java | 24 ++ .../tuscany/sca/guardian/itests/TestInterface.java | 26 ++ 30 files changed, 1714 insertions(+) create mode 100644 sandbox/dougsleite/guardian-model/.classpath create mode 100644 sandbox/dougsleite/guardian-model/.project create mode 100644 sandbox/dougsleite/guardian-model/pom.xml create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/ApplyUpdateFailureException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch2.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Node.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant1Launch.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant2Launch.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryServiceFailureException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/TestInterface.java (limited to 'sandbox/dougsleite') diff --git a/sandbox/dougsleite/guardian-model/.classpath b/sandbox/dougsleite/guardian-model/.classpath new file mode 100644 index 0000000000..8b0ba27bfa --- /dev/null +++ b/sandbox/dougsleite/guardian-model/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sandbox/dougsleite/guardian-model/.project b/sandbox/dougsleite/guardian-model/.project new file mode 100644 index 0000000000..2383adb712 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/.project @@ -0,0 +1,23 @@ + + + guardian-model + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder + + + + + + org.eclipse.jdt.core.javanature + org.devzuz.q.maven.jdt.core.mavenNature + + diff --git a/sandbox/dougsleite/guardian-model/pom.xml b/sandbox/dougsleite/guardian-model/pom.xml new file mode 100644 index 0000000000..82a1bd5c87 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.5-SNAPSHOT + ../../pom.xml + + tuscany-guardian-model + Guardian Model + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + 1.5-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.5-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.5-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.5-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 1.5-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.5-SNAPSHOT + runtime + + + + junit + junit + 4.5 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.guardian + ${pom.name} + org.apache.tuscany.sca.guardian* + + + + + + + diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java new file mode 100644 index 0000000000..848c4a874d --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +public interface BlockingInterface { + + //@OneWay + public void block(); + + //@OneWay + public void unblock(); + + public boolean isBlocked(); +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java new file mode 100644 index 0000000000..1b3cd72ead --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java @@ -0,0 +1,74 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +import java.util.LinkedList; +import java.util.List; + +public class Context { + + public static Context CURRENT_CONTEXT = new Context("CURRENT_CONTEXT"); + public static Context INIT_CONTEXT = new Context("INIT_CONTEXT"); + private String name; + private List exceptionList; + + public Context(String name) { + this.name = name; + this.exceptionList = new LinkedList(); + } + + public Context(String name, List exceptionList) { + this.name = name; + this.exceptionList = exceptionList; + } + + public void addException(GlobalException ex) { + this.exceptionList.add(ex); + } + + public void setExceptionList(List exceptionList) { + this.exceptionList = exceptionList; + } + + public List getExceptionList() { + return this.exceptionList; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object obj) { + return (obj instanceof Context && + (((Context) obj).getName().equals(this.getName()) || + this == Context.CURRENT_CONTEXT || + ((Context) obj) == Context.CURRENT_CONTEXT)); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java new file mode 100644 index 0000000000..c500a32701 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java @@ -0,0 +1,87 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +public class GlobalException extends RuntimeException { + + private Context signalingContext; + private Context targetContext; //Assigned by the recovery rules + private String signalingParticipant; + + public GlobalException() { + super(); + } + + public GlobalException(String message) { + super(message); + } + + public GlobalException(String message, Throwable cause) { + super(message, cause); + } + + public GlobalException(Throwable cause) { + super(cause); + } + + private void init() { + } + + /** + * @return the signalingContext + */ + public Context getSignalingContext() { + return signalingContext; + } + + /** + * @param signalingContext the signalingContext to set + */ + public void setSignalingContext(Context signalingContext) { + this.signalingContext = signalingContext; + } + + /** + * @return the targetContext + */ + public Context getTargetContext() { + return targetContext; + } + + /** + * @param targetContext the targetContext to set + */ + public void setTargetContext(Context targetContext) { + this.targetContext = targetContext; + } + + /** + * @return the signalingProcess + */ + public String getSignalingParticipant() { + return signalingParticipant; + } + + /** + * @param signalingProcess the signalingProcess to set + */ + public void setSignalingParticipant(String signalingProcess) { + this.signalingParticipant = signalingProcess; + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java new file mode 100644 index 0000000000..12d7cf478b --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java @@ -0,0 +1,26 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +public interface GuardianGroup extends GuardianPrimitives { + + public void addGuardianMember(GuardianMember guardianMember); + + public boolean removeGuardianMember(GuardianMember guardianMember); +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java new file mode 100644 index 0000000000..ee78dadddf --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java @@ -0,0 +1,180 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.osoa.sca.annotations.Scope; +import org.apache.tuscany.sca.guardian.exceptions.*; +import org.osoa.sca.annotations.Service; + +@Service(GuardianGroup.class) +@Scope("COMPOSITE") +public class GuardianGroupImpl implements GuardianGroup { + + List guardianMembers; + + public GuardianGroupImpl() { + guardianMembers = new LinkedList(); + } + + public void addGuardianMember(GuardianMember guardianMember) { + guardianMembers.add(guardianMember); + guardianMember.setUniqueParticipantID(guardianMembers.size() - 1); + } + + public void enableContext(Context context) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void removeContext() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void gthrow(GlobalException ex, List participantList) { + + //1)Ivoked by a GuardianMember instance through the gthrow method + //2)Notify all participants about the exception (FIFO atomic broadcast model) - it will cause the suspension of all participants + // 2.1)Invoke the gthrow of the guardian members associated with the participants on participantList + + //Sends a message representing the exception to the other guardian members + if (participantList == null) { + for (GuardianMember g : guardianMembers) { + if (!g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) { + //g.gthrow(ex, participantList); + g.gthrow(null, null); + } + } + } else { + for (GuardianMember g : guardianMembers) { + if (participantList.contains(g.getCurrentContext())) { + //g.gthrow(ex, participantList); + g.gthrow(null, null); + } + } + } + + //Check if the participants are blocked + List flags = new ArrayList(guardianMembers.size()); + for (int i = 0; i < guardianMembers.size(); i++) { + if (guardianMembers.get(i).getService().isBlocked()) { + flags.add(i, 1); + } else { + flags.add(i, 0); + } + } + + //Wait until all participants are blocked + while (flags.contains(0)) { + try { + Thread.sleep(5000); + } catch (InterruptedException ex1) { + Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1); + } + } + + //3)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules + for (GuardianMember g : guardianMembers) { + g.addException(new SuspendException()); + } + // 3.1) recovery_rules < signaled exceptions + context information of all participant > target context + exception to raise + + //Simpleste Recovery Rule: broadcast the exception for all participants - FIXME: hardcoded +// for (GuardianMemberImpl g : guardianMembers) { +// ex.setTargetContext(Context.CURRENT_CONTEXT); +// g.addException(ex); +// } + + //HARDCODED - SERVER-BACKUP EXAMPLE + //Rule 1 + if (ex instanceof JoinException) { + if (guardianMembers.size() > 1) { + + PrimaryExistsException primaryExists = new PrimaryExistsException(); + primaryExists.setTargetContext(new Context("MAIN")); + + BackupJoinedException backupJoined = new BackupJoinedException(); + backupJoined.setTargetContext(new Context("PRIMARY")); + + for (GuardianMember g : guardianMembers) { + //let p = JoinException.signaler + if (g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) { + g.addException(primaryExists); + System.out.println("adding PrimaryExistsException to " + g.getParticipantIdentifier()); + } else { + g.addException(backupJoined); + System.out.println("adding BackupJoinedException to " + g.getParticipantIdentifier()); + } + } + } + } //Rule 2 + else if (ex instanceof PrimaryFailedException) { + + PrimaryFailedException primaryFailedInit = new PrimaryFailedException(); + primaryFailedInit.setTargetContext(Context.INIT_CONTEXT); + + PrimaryFailedException primaryFailedMain = new PrimaryFailedException(); + primaryFailedMain.setTargetContext(new Context("MAIN")); + + for (GuardianMember g : guardianMembers) { + if (g.getCurrentContext().getName().equals("PRIMARY")) { + System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier()); + g.addException(primaryFailedInit); + } else if (g.getCurrentContext().getName().equals("BACKUP")) { + System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier()); + g.addException(primaryFailedMain); + } + } + } //Rule 3 + else if (ex instanceof BackupFailedException) { + + BackupFailedException backupFailedPrimary = new BackupFailedException(); + backupFailedPrimary.setTargetContext(new Context("PRIMARY")); + + BackupFailedException backupFailedInit = new BackupFailedException(); + backupFailedInit.setTargetContext(Context.INIT_CONTEXT); + + for (GuardianMember g : guardianMembers) { + if (g.getCurrentContext().getName().equals("PRIMARY")) { + System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier()); + g.addException(backupFailedPrimary); + } else if (g.getCurrentContext().getName().equals("BACKUP")) { + System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier()); + g.addException(backupFailedInit); + } + } + + } + } + + public boolean propagate(GlobalException ex) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void checkExceptionStatus() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean removeGuardianMember(GuardianMember guardianMember) { + return this.guardianMembers.remove(guardianMember); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java new file mode 100644 index 0000000000..460a89ce2d --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java @@ -0,0 +1,36 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +public interface GuardianMember extends GuardianPrimitives { + + public void addException(GlobalException ex); + + public void setService(BlockingInterface service); + + public void removeService(); + + public Context getCurrentContext(); + + public BlockingInterface getService(); + + public String getParticipantIdentifier(); + + public void setUniqueParticipantID(int id); +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java new file mode 100644 index 0000000000..5edecf4bcd --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java @@ -0,0 +1,209 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Destroy; + +@Scope("COMPOSITE") +public class GuardianMemberImpl implements GuardianMember { + + private Stack contextList; + private BlockingInterface service; + private Queue exceptionQueue; + @Reference(name = "guardian_group", required = true) + public GuardianGroup guardianGroup; + private int id; + + public GuardianMemberImpl() { + contextList = new Stack(); + exceptionQueue = new LinkedList(); + } + + @Init + public void init() { + guardianGroup.addGuardianMember(this); + } + + @Destroy + public void destroy() { + guardianGroup.removeGuardianMember(this); + } + + public void addException(GlobalException ex) { + exceptionQueue.add(ex); + } + + public void setService(BlockingInterface service) { + this.service = service; + } + + public Context getCurrentContext() { + return contextList.peek(); + } + + public BlockingInterface getService() { + return service; + } + + public void enableContext(Context context) { + //Update the context list with the related set of exceptions + contextList.push(context); + + if (contextList.size() == 1) { + gthrow(new JoinException(), null); + } + + } + + public void removeContext() { + if (!contextList.isEmpty()) { + contextList.pop(); + } + } + + //Adapt to allow a regular expression + //If participantList is null then signal to ALL participants + public void gthrow(GlobalException ex, List participantList) { + //1)Block the participant until raise an exception + if (!service.isBlocked()) { + service.block(); + + if (ex != null) { + //Set the exception's parameters + ex.setSignalingContext(getCurrentContext()); + ex.setSignalingParticipant(getParticipantIdentifier()); + + guardianGroup.gthrow(ex, participantList); + } + + //if (participantList == null || !participantList.contains(getParticipantIdentifier())) { +// if (getParticipantIdentifier().equals(ex.getSignalingParticipant())) { +// //2A)Call the gthrow of the GuardianGroup - communicate with other guardian members +// System.out.println("HERE AT " + getParticipantIdentifier()); +// guardianGroup.gthrow(ex, participantList); +// } + + } + + + //*Is here the best place to receive such kind of msg? + // + //2B)When receive exception_msg from GuardianGroup do + // if participant is not suspended then suspend it + // if participant supports interrupts then + // interrupt it, add SuspendException in the exception_queue, and invoke checkExceptionStatus + // else invoke checkExceptionStatus periodically + // + //4)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules + // 4.1) recovery_rules < signaled exceptions + context_list of all participant > target context + exception to raise + // 4.2) raise the resolved exception in each participant -> it goes to the exception_queue + + } + + public boolean propagate(GlobalException ex) { + //1)Compares the current context with the exception's target context + return !getCurrentContext().equals(ex.getTargetContext()); + } + + public void checkExceptionStatus() throws GlobalException { + //1)Chek the exception queue + // 1.1) if exception_queue is empty then return + // else if first element on the exception_queue is SuspendException then + // the method blocks until the next exception is received. The method raises the first non-SuspendException in the queue + + GlobalException exc; + + if ((exc = exceptionQueue.peek()) == null) { + System.out.println(getParticipantIdentifier() + "#No exception on exception queue"); + return; + } else { + while ((exc = exceptionQueue.peek()) instanceof SuspendException) { + try { + Thread.sleep(5000); + } catch (InterruptedException ex) { + Logger.getLogger(GuardianMemberImpl.class.getName()).log(Level.SEVERE, null, ex); + } + exceptionQueue.poll(); + } + + service.unblock(); + +// if (exc != null) { +// System.out.println("\n" + getParticipantIdentifier() + "#"); +// System.out.println("Exc: " + exc); +// System.out.println("TargetContext: " + exc.getTargetContext().getName()); +// System.out.println("Signaling Participant: " + exc.getSignalingParticipant()); +// System.out.println("Current Context: " + getCurrentContext().getName()); +// System.out.println("Equals: " + exc.getTargetContext().equals(getCurrentContext()) + "\n"); +// } + + //FIX-ME: ex.targetContext() matches the participant id -> could use regular expressions + //Eg. ex.targetContext(): Main and participant id: Init/Main/Backup -> should throw the exception + String[] contexts = getParticipantIdentifier().split("\\."); + if (exc != null) { + for (int i = contexts.length - 1; i > 0; i--) { + if (exc.getTargetContext().equals(new Context(contexts[i]))) { + System.out.println(getParticipantIdentifier() + "#Returning an exception"); + exceptionQueue.poll(); + throw exc; + } + } + } + +// if (exc != null && exc.getTargetContext().equals(getCurrentContext())) { +// System.out.println(getParticipantIdentifier() + "#Returning an exception"); +// exceptionQueue.poll(); +// throw exc; +// } + + return; + } + + } + + public String getParticipantIdentifier() { + //1) Return the participant identifier -> context list dot separated + StringBuffer id = new StringBuffer(); + id.append(this.id + "." + Context.INIT_CONTEXT.getName()); + for (int i = 0; i < contextList.size(); i++) { + id.append("." + contextList.get(i).getName()); +// if (i + 1 != contextList.size()) { +// id.append("."); +// } + } + return id.toString(); + } + + public void setUniqueParticipantID(int id) { + this.id = id; + } + + public void removeService() { + this.service = null; + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java new file mode 100644 index 0000000000..a7710f811e --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java @@ -0,0 +1,37 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +import java.util.List; + +public interface GuardianPrimitives { + + //Methods to manage contexts + public void enableContext(Context context); + + public void removeContext(); + + //Methods to control the signaling of exceptions + public void gthrow(GlobalException ex, List participantList); + + public boolean propagate(GlobalException ex); + + //Method to check pending global exceptions + public void checkExceptionStatus(); +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java new file mode 100644 index 0000000000..b14ebeac2b --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.guardian; + +class JoinException extends GlobalException { + + public JoinException() { + super(); + } + + public JoinException(String message) { + super(message); + } + + public JoinException(String message, Throwable cause) { + super(message, cause); + } + + public JoinException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java new file mode 100644 index 0000000000..04e892f4bd --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +class LeaveException extends GlobalException { + + public LeaveException() { + super(); + } + + public LeaveException(String message) { + super(message); + } + + public LeaveException(String message, Throwable cause) { + super(message, cause); + } + + public LeaveException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java new file mode 100644 index 0000000000..b7ede6d530 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +class SuspendException extends GlobalException { + + public SuspendException() { + super(); + } + + public SuspendException(String message) { + super(message); + } + + public SuspendException(String message, Throwable cause) { + super(message, cause); + } + + public SuspendException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java new file mode 100644 index 0000000000..81e3844280 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian; + +public class UnhandledException extends GlobalException { + + public UnhandledException() { + super(); + } + + public UnhandledException(String message) { + super(message); + } + + public UnhandledException(String message, Throwable cause) { + super(message, cause); + } + + public UnhandledException(Throwable cause) { + super(cause); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java new file mode 100644 index 0000000000..c4b2dd7de5 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.exceptions; + +import org.apache.tuscany.sca.guardian.*; + +public class BackupFailedException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java new file mode 100644 index 0000000000..1fffa14663 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.exceptions; + +import org.apache.tuscany.sca.guardian.GlobalException; + +public class BackupJoinedException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java new file mode 100644 index 0000000000..6d358c281e --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.exceptions; + +import org.apache.tuscany.sca.guardian.GlobalException; + +public class PrimaryExistsException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java new file mode 100644 index 0000000000..7f6b73cd05 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.exceptions; + +import org.apache.tuscany.sca.guardian.*; + +public class PrimaryFailedException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite b/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite new file mode 100644 index 0000000000..e2e27937d6 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/ApplyUpdateFailureException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/ApplyUpdateFailureException.java new file mode 100644 index 0000000000..a40667ff8d --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/ApplyUpdateFailureException.java @@ -0,0 +1,22 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +public class ApplyUpdateFailureException extends RuntimeException { +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java new file mode 100644 index 0000000000..11ede178d0 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class GuardianLaunch { + + public static void main(String... args) throws IOException { + + SCADomain scaDomain = SCADomain.newInstance("guardiangroup.composite"); + System.in.read(); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch.java new file mode 100644 index 0000000000..bb4b41163f --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Launch { + + public static void main(String... args) throws IOException { + SCADomain scaDomain = SCADomain.newInstance("server-backup.composite"); + + System.out.println("Starting participat1..."); + Node c = scaDomain.getService(Node.class, "Participant1"); + c.execute(); + + System.in.read(); + + System.out.println("Starting participant2..."); + Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.execute(); + + System.in.read(); + + System.out.println("Forcing exception ocurrence at participant1..."); + TestInterface t = scaDomain.getService(TestInterface.class, "Participant1"); + t.forcePrimaryServiceFailureException(); + + System.in.read(); + + scaDomain.close(); + } +} + diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch2.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch2.java new file mode 100644 index 0000000000..7b9e3fc1de --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch2.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Launch2 { + + public static void main(String... args) throws IOException { + SCADomain scaDomain = SCADomain.newInstance("server-backup.composite"); + + System.out.println("Starting participat1..."); + Node c = scaDomain.getService(Node.class, "Participant1"); + c.execute(); + + System.in.read(); + + System.out.println("Starting participant2..."); + Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.execute(); + + System.in.read(); + + System.out.println("Forcing exception ocurrence at participant2..."); + TestInterface t = scaDomain.getService(TestInterface.class, "Participant2"); + t.forceApplyUpdateFailureException(); + + System.in.read(); + + scaDomain.close(); + } +} + diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Node.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Node.java new file mode 100644 index 0000000000..6557aa4732 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Node.java @@ -0,0 +1,34 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import org.apache.tuscany.sca.guardian.BlockingInterface; +import org.osoa.sca.annotations.OneWay; + +public interface Node extends BlockingInterface { + + @OneWay + public void execute(); + + public void sendUpdate(String s); + + public void applyUpdate(); + + public boolean isExecuting(); +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java new file mode 100644 index 0000000000..86d2e9bbc6 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java @@ -0,0 +1,277 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.tuscany.sca.guardian.Context; +import org.apache.tuscany.sca.guardian.GlobalException; +import org.apache.tuscany.sca.guardian.GuardianMember; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.apache.tuscany.sca.guardian.exceptions.BackupFailedException; +import org.apache.tuscany.sca.guardian.exceptions.BackupJoinedException; +import org.apache.tuscany.sca.guardian.exceptions.PrimaryExistsException; +import org.apache.tuscany.sca.guardian.exceptions.PrimaryFailedException; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.OneWay; + +@Scope("COMPOSITE") +public class NodeImpl implements Node, TestInterface { + + private static int PRIMARY = 0; + private static int BACKUP = 1; + private boolean isBlocked; + private Context mainContext; + private Context primaryContext; + private Context backupContext; + private List exListMain; + private List exListPrimary; + private int role; + private boolean isExecuting; + private String pID; + private Queue updates; + @Reference(name = "guardian_member", required = true) + public GuardianMember gm; + @Reference(name = "node", required = true) + public Node node; + private boolean forcePSFException; + private boolean forceAUFException; + + public NodeImpl() { + exListMain = new LinkedList(); + exListMain.add(new PrimaryFailedException()); + exListMain.add(new PrimaryExistsException()); + + exListPrimary = new LinkedList(); + exListPrimary.add(new BackupFailedException()); + exListPrimary.add(new BackupJoinedException()); + exListPrimary.add(new PrimaryServiceFailureException()); + + mainContext = new Context("MAIN", exListMain); + primaryContext = new Context("PRIMARY", exListPrimary); + backupContext = new Context("BACKUP", null); + + updates = new LinkedList(); + + isBlocked = false; + isExecuting = false; + + node = null; + + forcePSFException = false; + forceAUFException = false; + } + + @Init + public void init() { + gm.setService(this); + pID = gm.getParticipantIdentifier(); + } + + @Destroy + public void destroy() { + gm.removeService(); + } + + public boolean isExecuting() { + return isExecuting; + } + + @OneWay + public void execute() { + isExecuting = true; + gm.enableContext(mainContext); + role = PRIMARY; + + while (true) { + try { + System.out.println(pID + "#Main context: "); + sleep(pID + "#Sleeping at main context...", 4000); + + gm.checkExceptionStatus(); + + if (role == PRIMARY) { + //Config as primary then... + primaryService(); + } else { + //Config as backup then... + backupService(); + } + + + } catch (PrimaryExistsException ex) { + System.out.println(pID + "# Exception captured!: PrimaryExistsException"); + System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex)); + + if (gm.propagate(ex)) { + throw ex; + } + + role = BACKUP; + } catch (PrimaryFailedException ex) { + System.out.println(pID + "# Exception captured!: PrimaryFailedException"); + System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex)); + + if (gm.propagate(ex)) { + //throw ex; + ex.printStackTrace(); + return; + } + role = PRIMARY; + + } catch (BackupFailedException ex) { + System.out.println(pID + "# Exception captured!: BackupFailedException"); + System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex)); + + if (gm.propagate(ex)) { + //throw ex; + ex.printStackTrace(); + return; + } + } + } + } + + private void sleep(String msg, int millis) { + try { + System.out.println(msg); + Thread.sleep(millis); + } catch (InterruptedException ex) { + Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private void primaryService() { + boolean backupAvailable = false; + int upcount = 1; + + while (true) { + + gm.enableContext(primaryContext); + + try { + System.out.println(pID + "#Primary context: "); + sleep(pID + "#Sleeping at primary context...", 4000); + gm.checkExceptionStatus(); + + //Process the request then... + System.out.println(pID + "#Processing the request..."); + + //Check for an internal error + if (forcePSFException) { + throw new PrimaryServiceFailureException(); + } + + if (backupAvailable && node.isExecuting()) { + node.sendUpdate("Update " + upcount); + upcount++; + } else { + System.out.println(pID + "#No backup available to send updates!"); + } + //send the reply to the client + System.out.println(pID + "#Sending the reply to the client..."); + + } catch (PrimaryServiceFailureException ex) { + System.out.println(pID + "# Exception captured!: PrimaryServiceFailureException"); + gm.gthrow(new PrimaryFailedException(), null); + } catch (BackupFailedException ex) { + System.out.println(pID + "# Exception captured!: BackupFailedException"); + backupAvailable = false; + } catch (BackupJoinedException ex) { + System.out.println(pID + "# Exception captured!: BackupJoinedException"); + backupAvailable = true; + } finally { + gm.removeContext(); + } + } + } + + private void backupService() { + while (true) { + + gm.enableContext(backupContext); + + try { + System.out.println(pID + "#Backup context: "); + sleep(pID + "#Sleeping at backup service", 4000); + gm.checkExceptionStatus(); + + applyUpdate(); + + if (forceAUFException) { + throw new ApplyUpdateFailureException(); + } + + } catch (ApplyUpdateFailureException ex) { + System.out.println(pID + "# Exception captured!: ApplyUpdateFailureException"); + gm.gthrow(new BackupFailedException(), null); + } finally { + gm.removeContext(); + } + } + } + + //FIXME - It is not working asynchronously + //@OneWay + public void block() { + System.out.println(pID + "#Participant blocked!"); + isBlocked = true; + +// while (isBlocked) { +// try { +// Thread.sleep(5000); +// } catch (InterruptedException ex) { +// Logger.getLogger(ComponentImpl.class.getName()).log(Level.SEVERE, null, ex); +// } +// } + } + + public boolean isBlocked() { + return isBlocked; + } + + //@OneWay + public void unblock() { + System.out.println(pID + "#Participant unblocked!"); + isBlocked = false; + } + + public void sendUpdate(String update) { + System.out.println(pID + "#Receiving updates from primary: " + update); + updates.offer(update); + } + + public void applyUpdate() { + System.out.println(pID + "#Applying the updates received from the primary: " + updates.poll()); + } + + public void forcePrimaryServiceFailureException() { + forcePSFException = true; + } + + public void forceApplyUpdateFailureException() { + forceAUFException = true; + } +} + diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant1Launch.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant1Launch.java new file mode 100644 index 0000000000..a5c360701a --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant1Launch.java @@ -0,0 +1,45 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.guardian.exceptions.PrimaryFailedException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Participant1Launch { + + public static void main(String... args) throws IOException { + SCADomain scaDomain = SCADomain.newInstance("participant1.composite"); + + try { + + System.out.println("Starting participat1..."); + Node c = scaDomain.getService(Node.class, "Participant1"); + c.execute(); + + System.in.read(); + + } catch (PrimaryFailedException ex) { + System.out.println("Init#Exception captured!: PrimaryFailedException"); + + } finally { + scaDomain.close(); + } + } +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant2Launch.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant2Launch.java new file mode 100644 index 0000000000..3478e4e105 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Participant2Launch.java @@ -0,0 +1,45 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.guardian.exceptions.PrimaryFailedException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Participant2Launch { + + public static void main(String... args) throws IOException { + SCADomain scaDomain = SCADomain.newInstance("participant2.composite"); + + try { + + System.out.println("Starting participant2..."); + Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.execute(); + + System.in.read(); + + } catch (PrimaryFailedException ex) { + System.out.println("Init#Exception captured!: PrimaryFailedException"); + + } finally { + scaDomain.close(); + } + } +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryServiceFailureException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryServiceFailureException.java new file mode 100644 index 0000000000..3e8f6af7a6 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryServiceFailureException.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +import org.apache.tuscany.sca.guardian.GlobalException; + +public class PrimaryServiceFailureException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/TestInterface.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/TestInterface.java new file mode 100644 index 0000000000..5368de138f --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/TestInterface.java @@ -0,0 +1,26 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.guardian.itests; + +public interface TestInterface { + + public void forcePrimaryServiceFailureException(); + + public void forceApplyUpdateFailureException(); +} -- cgit v1.2.3