You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Aleksey Plekhanov (Jira)" <ji...@apache.org> on 2020/11/05 10:28:00 UTC

[jira] [Commented] (IGNITE-13633) thin clients cannot access the Ignite Service deployed through UriDeploymentSpi( java.lang.ClassNotFoundException)

    [ https://issues.apache.org/jira/browse/IGNITE-13633?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17226631#comment-17226631 ] 

Aleksey Plekhanov commented on IGNITE-13633:
--------------------------------------------

Root cause: Implementations of {{ServiceDescriptor}} know nothing about deployment SPI, every {{ServiceDescriptor.serviceClass()}} usage is prone to this error (thin client services, .NET services, services system view, public API). Simlified reproducer:

{code:java}
public class ServiceWithDeploymentSpiTest extends GridCommonAbstractTest {
    private Path srcTmpDir;

    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
        cfg.setDeploymentSpi(new LocalDeploymentSpi());
        return cfg;
    }

    @Before
    public void prepare() throws IOException {
        srcTmpDir = Files.createTempDirectory(getClass().getSimpleName());
    }

    @After
    public void cleanup() {
        U.delete(srcTmpDir);
    }

    @Test
    public void testServiceWithDeploymentSpi() throws Exception {
        URLClassLoader clsLdr = prepareClassLoader();
        Class<?> cls = clsLdr.loadClass("MyServiceImpl");
        Service srvc = (Service)cls.newInstance();
        Ignite ignite = startGrid(0);
        DeploymentSpi depSpi = ignite.configuration().getDeploymentSpi();
        depSpi.register(clsLdr, srvc.getClass());
        ignite.services().deployClusterSingleton("test-service", srvc);
        for (ServiceDescriptor desc : ignite.services().serviceDescriptors()) {
            if ("test-service".equals(desc.name()))
                assertEquals(cls, desc.serviceClass());
        }
    }

    private URLClassLoader prepareClassLoader() throws Exception {
        String src = "import org.apache.ignite.services.Service;\n" +
            "import org.apache.ignite.services.ServiceContext;\n" +
            "public class MyServiceImpl implements Service {\n" +
            "    @Override public void cancel(ServiceContext ctx) {}\n" +
            "    @Override public void init(ServiceContext ctx) throws Exception {}\n" +
            "    @Override public void execute(ServiceContext ctx) throws Exception {}\n" +
            "}";
        Files.createDirectories(srcTmpDir);
        File srcFile = new File(srcTmpDir.toFile(), "MyServiceImpl.java");
        Path srcFilePath = Files.write(srcFile.toPath(), src.getBytes(StandardCharsets.UTF_8));
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        compiler.run(null, null, null, srcFilePath.toString());
        assertTrue("Failed to remove source file.", srcFile.delete());
        return new URLClassLoader(new URL[] {srcTmpDir.toUri().toURL()});
    }
}
{code}


> thin clients cannot access the Ignite Service deployed through UriDeploymentSpi( java.lang.ClassNotFoundException)
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: IGNITE-13633
>                 URL: https://issues.apache.org/jira/browse/IGNITE-13633
>             Project: Ignite
>          Issue Type: Bug
>          Components: managed services, thin client
>    Affects Versions: 2.9
>            Reporter: xingzhou
>            Assignee: Aleksey Plekhanov
>            Priority: Critical
>             Fix For: 2.9.1
>
>         Attachments: ignite-deploy.zip
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> When the thin client is used to call the ignite service( use ignite-urideploy ), the clientserviceinvokerequest will get the service classes, the local classloader is used, and the classes cannot be found. Therefore, the ignite-urideploy classloader should be added



--
This message was sent by Atlassian Jira
(v8.3.4#803005)