Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ private static Map<UUID, Integer> serviceTopology(IgniteInternalCache<Object, Ob

GridServiceDeployment dep = (GridServiceDeployment)e.getValue();

ServiceDescriptorImpl desc = new ServiceDescriptorImpl(dep);
ServiceDescriptorImpl desc = new ServiceDescriptorImpl(ctx, dep);

try {
GridServiceAssignments assigns = (GridServiceAssignments)serviceCache().getForcePrimary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ public ServiceDeploymentManager deployment() {
}

for (ServiceConfiguration srvcCfg : prepCfgs.cfgs)
staticServicesInfo.add(new ServiceInfo(ctx.localNodeId(), IgniteUuid.randomUuid(), srvcCfg, true));
staticServicesInfo.add(new ServiceInfo(ctx, ctx.localNodeId(), IgniteUuid.randomUuid(), srvcCfg, true));
}

return staticServicesInfo;
Expand Down Expand Up @@ -1613,7 +1613,7 @@ else if (req instanceof ServiceUndeploymentRequest)
"affinity cache is not found, cfg=" + cfg);
}
else {
ServiceInfo desc = new ServiceInfo(snd.id(), reqSrvcId, cfg);
ServiceInfo desc = new ServiceInfo(ctx, snd.id(), reqSrvcId, cfg);

registeredServices.put(reqSrvcId, desc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.managers.deployment.GridDeployment;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.services.Service;
Expand All @@ -38,6 +40,9 @@ public class ServiceDescriptorImpl implements ServiceDescriptor {
/** */
private static final long serialVersionUID = 0L;

/** Kernel context. */
private final GridKernalContext ctx;

/** Configuration. */
@GridToStringInclude
private final GridServiceDeployment dep;
Expand All @@ -46,10 +51,14 @@ public class ServiceDescriptorImpl implements ServiceDescriptor {
@GridToStringInclude
private Map<UUID, Integer> top;

/** Service class. */
private volatile Class<? extends Service> srvcCls;

/**
* @param dep Deployment.
*/
public ServiceDescriptorImpl(GridServiceDeployment dep) {
public ServiceDescriptorImpl(GridKernalContext ctx, GridServiceDeployment dep) {
this.ctx = ctx;
this.dep = dep;
}

Expand All @@ -63,12 +72,26 @@ public ServiceDescriptorImpl(GridServiceDeployment dep) {
ServiceConfiguration cfg = dep.configuration();

if (cfg instanceof LazyServiceConfiguration) {
if (srvcCls != null)
return srvcCls;

String clsName = ((LazyServiceConfiguration)cfg).serviceClassName();

try {
return (Class<? extends Service>)Class.forName(clsName);
srvcCls = (Class<? extends Service>)Class.forName(clsName);

return srvcCls;
}
catch (ClassNotFoundException e) {
GridDeployment srvcDep = ctx.deploy().getDeployment(clsName);

if (srvcDep != null) {
srvcCls = (Class<? extends Service>)srvcDep.deployedClass(clsName);

if (srvcCls != null)
return srvcCls;
}

throw new IgniteException("Failed to find service class: " + clsName, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.managers.deployment.GridDeployment;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.lang.IgniteUuid;
Expand All @@ -37,6 +39,9 @@ public class ServiceInfo implements ServiceDescriptor {
/** */
private static final long serialVersionUID = 0L;

/** Context. */
private final GridKernalContext ctx;

/** Origin node ID. */
private final UUID originNodeId;

Expand All @@ -53,13 +58,16 @@ public class ServiceInfo implements ServiceDescriptor {
@GridToStringInclude
private volatile Map<UUID, Integer> top;

/** Service class. */
private volatile Class<? extends Service> srvcCls;

/**
* @param originNodeId Initiating node id.
* @param srvcId Service id.
* @param cfg Service configuration.
*/
public ServiceInfo(@NotNull UUID originNodeId, @NotNull IgniteUuid srvcId, @NotNull ServiceConfiguration cfg) {
this(originNodeId, srvcId, cfg, false);
public ServiceInfo(GridKernalContext ctx, @NotNull UUID originNodeId, @NotNull IgniteUuid srvcId, @NotNull ServiceConfiguration cfg) {
this(ctx, originNodeId, srvcId, cfg, false);
}

/**
Expand All @@ -68,8 +76,9 @@ public ServiceInfo(@NotNull UUID originNodeId, @NotNull IgniteUuid srvcId, @NotN
* @param cfg Service configuration.
* @param staticCfg Statically configured flag.
*/
public ServiceInfo(@NotNull UUID originNodeId, @NotNull IgniteUuid srvcId, @NotNull ServiceConfiguration cfg,
public ServiceInfo(@NotNull GridKernalContext ctx, @NotNull UUID originNodeId, @NotNull IgniteUuid srvcId, @NotNull ServiceConfiguration cfg,
boolean staticCfg) {
this.ctx = ctx;
this.originNodeId = originNodeId;
this.srvcId = srvcId;
this.cfg = cfg;
Expand Down Expand Up @@ -116,15 +125,28 @@ public IgniteUuid serviceId() {
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public Class<? extends Service> serviceClass() {
if (cfg instanceof LazyServiceConfiguration) {
if (srvcCls != null)
return srvcCls;

String clsName = ((LazyServiceConfiguration)cfg).serviceClassName();

try {
return (Class<? extends Service>)Class.forName(clsName);
srvcCls = (Class<? extends Service>)Class.forName(clsName);

return srvcCls;
}
catch (ClassNotFoundException e) {
GridDeployment srvcDep = ctx.deploy().getDeployment(clsName);

if (srvcDep != null) {
srvcCls = (Class<? extends Service>)srvcDep.deployedClass(clsName);

if (srvcCls != null)
return srvcCls;
}

throw new IgniteException("Failed to find service class: " + clsName, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.ToIntFunction;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.services.Service;
import org.apache.ignite.services.ServiceDescriptor;
import org.apache.ignite.spi.deployment.DeploymentSpi;
import org.apache.ignite.spi.deployment.local.LocalDeploymentSpi;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
Expand All @@ -61,12 +66,6 @@ public class ServiceHotRedeploymentViaDeploymentSpiTest extends GridCommonAbstra
return cfg;
}

/** */
@BeforeClass
public static void check() {
Assume.assumeTrue(isEventDrivenServiceProcessorEnabled());
}

/** */
@Before
public void prepare() throws IOException {
Expand All @@ -79,11 +78,64 @@ public void cleanup() {
U.delete(srcTmpDir);
}

/** */
@Test
public void testServiceDeploymentViaDeploymentSpi() throws Exception {
URLClassLoader clsLdr = prepareClassLoader(1);
Class<?> cls = clsLdr.loadClass("MyRenewServiceImpl");

MyRenewService srvc = (MyRenewService)cls.newInstance();

assertEquals(1, srvc.version());

try {
Ignite ignite = startGrid(0);

final DeploymentSpi depSpi = ignite.configuration().getDeploymentSpi();

depSpi.register(clsLdr, srvc.getClass());

ignite.services().deployClusterSingleton(SERVICE_NAME, srvc);

Class<?> srvcCls = serviceClass(ignite, SERVICE_NAME);

assertSame(cls, srvcCls);

assertEquals(1, ignite.services().serviceProxy(SERVICE_NAME, MyRenewService.class, false)
.version());
}
finally {
stopAllGrids();
}
}

/** */
@Test
public void testServiceHotRedeploymentNode() throws Exception {
serviceHotRedeploymentTest(
ignite -> ignite.services().serviceProxy(SERVICE_NAME, MyRenewService.class, false).version());
}

/** */
@Test
public void testServiceHotRedeploymentThinClient() throws Exception {
serviceHotRedeploymentTest(ignite -> {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:10800"))) {
return client.services().serviceProxy(SERVICE_NAME, MyRenewService.class).version();
}
catch (Exception e) {
throw new IgniteException(e);
}
});
}

/**
* @throws Exception If failed.
*/
@Test
public void serviceHotRedeploymentTest() throws Exception {
private void serviceHotRedeploymentTest(ToIntFunction<Ignite> srvcFunc) throws Exception {
Assume.assumeTrue("Hot redeployment supported only by event driven service processor",
isEventDrivenServiceProcessorEnabled());

URLClassLoader clsLdr = prepareClassLoader(1);
Class<?> cls = clsLdr.loadClass("MyRenewServiceImpl");

Expand All @@ -99,8 +151,12 @@ public void serviceHotRedeploymentTest() throws Exception {
depSpi.register(clsLdr, srvc.getClass());

ignite.services().deployClusterSingleton(SERVICE_NAME, srvc);
MyRenewService proxy = ignite.services().serviceProxy(SERVICE_NAME, MyRenewService.class, false);
assertEquals(1, proxy.version());

Class<?> srvcCls = serviceClass(ignite, SERVICE_NAME);

assertSame(cls, srvcCls);

assertEquals(1, srvcFunc.applyAsInt(ignite));

ignite.services().cancel(SERVICE_NAME);
depSpi.unregister(srvc.getClass().getName());
Expand All @@ -111,14 +167,26 @@ public void serviceHotRedeploymentTest() throws Exception {
depSpi.register(clsLdr, srvc.getClass());

ignite.services().deployClusterSingleton(SERVICE_NAME, srvc);
proxy = ignite.services().serviceProxy(SERVICE_NAME, MyRenewService.class, false);
assertEquals(2, proxy.version());

assertNotSame(srvcCls, serviceClass(ignite, SERVICE_NAME));

assertEquals(2, srvcFunc.applyAsInt(ignite));
}
finally {
stopAllGrids();
}
}

/** */
private Class<?> serviceClass(Ignite ignite, String srvcName) {
for (ServiceDescriptor desc : ignite.services().serviceDescriptors()) {
if (srvcName.equals(desc.name()))
return desc.serviceClass();
}

return null;
}

/** */
public interface MyRenewService extends Service {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.ignite.services.Service;
import org.apache.ignite.services.ServiceConfiguration;
import org.apache.ignite.services.ServiceContext;
import org.apache.ignite.testframework.junits.GridTestKernalContext;
import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -44,7 +46,7 @@ public class ServiceInfoSelfTest {
private ServiceConfiguration cfg = configuration();

/** Subject under test. */
private ServiceInfo sut = new ServiceInfo(nodeId, srvcId, cfg);
private ServiceInfo sut = new ServiceInfo(new GridTestKernalContext(new GridTestLog4jLogger()), nodeId, srvcId, cfg);

/**
* Tests {@link ServiceInfo#configuration()}.
Expand Down