-
-
Save kamalcph/0f4175fdcfd2c4ef909150be5d896c56 to your computer and use it in GitHub Desktop.
package my.apache.ignite.examples.servicegrid; | |
import org.apache.ignite.services.Service; | |
public interface CalcService extends Service { | |
int add(int a, int b); | |
int sub(int a, int b); | |
} |
package my.apache.ignite.examples.servicegrid; | |
import java.util.concurrent.TimeUnit; | |
import org.apache.ignite.services.ServiceContext; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class CalcServiceImpl implements CalcService { | |
private static final long serialVersionUID = 1L; | |
private final Logger logger = LoggerFactory.getLogger(CalcServiceImpl.class); | |
public CalcServiceImpl() { | |
logger.info("CalcServiceImpl instantiated"); | |
} | |
@Override | |
public void cancel(ServiceContext ctx) { | |
logger.info("Service : {} cancelled", ctx.name()); | |
} | |
@Override | |
public void init(ServiceContext ctx) throws Exception { | |
logger.info(">>> Service : initing..", ctx.name()); | |
Thread.sleep(TimeUnit.MINUTES.toMillis(1)); | |
logger.info("Service : {} inited", ctx.name()); | |
} | |
@Override | |
public void execute(ServiceContext ctx) throws Exception { | |
logger.info("Service : {} executed", ctx.name()); | |
} | |
@Override | |
public int add(int a, int b) { | |
return a+b; | |
} | |
@Override | |
public int sub(int a, int b) { | |
return a-b; | |
} | |
} |
package my.apache.ignite.examples.servicegrid; | |
import java.io.IOException; | |
import org.apache.ignite.Ignite; | |
import org.apache.ignite.Ignition; | |
public class ServiceDeployer { | |
public static final String calcService = "CalcService"; | |
public ServiceDeployer() { | |
} | |
public static void main(String[] args) throws InterruptedException, IOException { | |
Ignite ignite = Ignition.start("examples/config/example-ignite.xml"); | |
CalcService calculator = new CalcServiceImpl(); | |
ignite.services().deployNodeSingleton(calcService, calculator); | |
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { | |
@Override | |
public void run() { | |
System.out.println(">>> Stopping the node"); | |
Ignition.stop(true); | |
} | |
})); | |
} | |
} |
import org.apache.ignite.Ignite; | |
import org.apache.ignite.Ignition; | |
public class ServiceUser { | |
public ServiceUser() { | |
} | |
public static void main(String[] args) throws InterruptedException { | |
Ignition.setClientMode(true); | |
final Ignite ignite = Ignition.start("examples/config/example-ignite.xml"); | |
CalcService calculator = ignite.services().serviceProxy(ServiceDeployer.calcService, CalcService.class, false); | |
int i = 0; | |
while (true) { | |
System.out.println(i++ + ". 2 + 2 = " + calculator.add(2, 2)); | |
Thread.sleep(100); | |
} | |
} | |
} |
Exception thrown when Node 2 joins the cluster
[2016-07-30 17:33:05,281] ERROR Failed to obtain remote job result policy for result from ComputeTask.result(..) method (will fail the whole task): GridJobResultImpl [job=C2V2 [c=ServiceProxyCallable [mtdName=add, svcName=CalcService, ignite=null]], sib=GridJobSiblingImpl [sesId=6505eab3651-9d717127-5b31-4138-b74f-14bedcaf91ae, jobId=8505eab3651-9d717127-5b31-4138-b74f-14bedcaf91ae, nodeId=efe17216-223f-4013-b462-cf486db19e59, isJobDone=false], jobCtx=GridJobContextImpl [jobId=8505eab3651-9d717127-5b31-4138-b74f-14bedcaf91ae, timeoutObj=null, attrs={}], node=TcpDiscoveryNode [id=efe17216-223f-4013-b462-cf486db19e59, addrs=[127.0.0.1], sockAddrs=[/127.0.0.1:47500], discPort=47500, order=30, intOrder=16, lastExchangeTime=1469880011620, loc=false, ver=1.6.0#20160518-sha1:0b22c45b, isClient=false], ex=class o.a.i.IgniteException: Service not found: CalcService, hasRes=true, isCancelled=false, isOccupied=true] (org.apache.ignite.internal.processors.task.GridTaskWorker)
class org.apache.ignite.IgniteException: Remote job threw user exception (override or implement ComputeTask.result(..) method if you would like to have automatic failover for this exception).
at org.apache.ignite.compute.ComputeTaskAdapter.result(ComputeTaskAdapter.java:101)
at org.apache.ignite.internal.processors.task.GridTaskWorker$3.apply(GridTaskWorker.java:912)
at org.apache.ignite.internal.processors.task.GridTaskWorker$3.apply(GridTaskWorker.java:905)
at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6491)
at org.apache.ignite.internal.processors.task.GridTaskWorker.result(GridTaskWorker.java:905)
at org.apache.ignite.internal.processors.task.GridTaskWorker.onResponse(GridTaskWorker.java:801)
at org.apache.ignite.internal.processors.task.GridTaskProcessor.processJobExecuteResponse(GridTaskProcessor.java:995)
at org.apache.ignite.internal.processors.task.GridTaskProcessor$JobMessageListener.onMessage(GridTaskProcessor.java:1220)
at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1219)
at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:847)
at org.apache.ignite.internal.managers.communication.GridIoManager.access$1700(GridIoManager.java:105)
at org.apache.ignite.internal.managers.communication.GridIoManager$5.run(GridIoManager.java:810)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: class org.apache.ignite.IgniteException: Service not found: CalcService
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2V2.execute(GridClosureProcessor.java:2031)
at org.apache.ignite.internal.processors.job.GridJobWorker$2.call(GridJobWorker.java:509)
at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6459)
at org.apache.ignite.internal.processors.job.GridJobWorker.execute0(GridJobWorker.java:503)
at org.apache.ignite.internal.processors.job.GridJobWorker.body(GridJobWorker.java:456)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at org.apache.ignite.internal.processors.job.GridJobProcessor.processJobExecuteRequest(GridJobProcessor.java:1161)
at org.apache.ignite.internal.processors.job.GridJobProcessor$JobExecutionListener.onMessage(GridJobProcessor.java:1766)
... 7 more
Caused by: class org.apache.ignite.internal.processors.service.GridServiceNotFoundException: Service not found: CalcService
at org.apache.ignite.internal.processors.service.GridServiceProxy$ServiceProxyCallable.call(GridServiceProxy.java:383)
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2V2.execute(GridClosureProcessor.java:2028)
... 14 more
Steps to reproduce the issue
Expectation - When node 2 joins the cluster, all the requests from the client should be redirected to the
CalcService in node 1 until the service in node 2 is ready. But, the requests are redirected to node 2
before service initialization.