Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 33FEC18F8F for ; Wed, 29 Apr 2015 14:04:37 +0000 (UTC) Received: (qmail 36659 invoked by uid 500); 29 Apr 2015 14:04:37 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 36611 invoked by uid 500); 29 Apr 2015 14:04:37 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 36570 invoked by uid 99); 29 Apr 2015 14:04:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2015 14:04:37 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [54.164.171.186] (HELO mx1-us-east.apache.org) (54.164.171.186) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2015 14:04:28 +0000 Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 3E3DD43DC3 for ; Wed, 29 Apr 2015 14:04:07 +0000 (UTC) Received: (qmail 35823 invoked by uid 99); 29 Apr 2015 14:04:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Apr 2015 14:04:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 45D9FE0215; Wed, 29 Apr 2015 14:04:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.incubator.apache.org Date: Wed, 29 Apr 2015 14:04:05 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [01/16] incubator-ignite git commit: # IGNITE-789 WIP. X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-ignite Updated Branches: refs/heads/ignite-sprint-4 edcf921cd -> d1a84a576 # IGNITE-789 WIP. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/da04a0ec Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/da04a0ec Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/da04a0ec Branch: refs/heads/ignite-sprint-4 Commit: da04a0ec96e3a6f4cf71a331a498b57686dbe1cd Parents: 8e31b7c Author: AKuznetsov Authored: Thu Apr 23 09:26:39 2015 +0700 Committer: AKuznetsov Committed: Thu Apr 23 09:26:39 2015 +0700 ---------------------------------------------------------------------- .../main/java/org/apache/ignite/Ignition.java | 19 +++++ .../org/apache/ignite/internal/IgnitionEx.java | 17 ++++ .../util/spring/IgniteSpringHelper.java | 11 +++ .../visor/cache/VisorCacheStartNearTask.java | 78 ++++++++++++++++++ .../visor/cache/VisorCacheStartTask.java | 86 ++++++++++++++++++++ .../util/spring/IgniteSpringHelperImpl.java | 39 ++++++++- 6 files changed, 246 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/core/src/main/java/org/apache/ignite/Ignition.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/Ignition.java b/modules/core/src/main/java/org/apache/ignite/Ignition.java index 8af5d4c..e0ddd6e 100644 --- a/modules/core/src/main/java/org/apache/ignite/Ignition.java +++ b/modules/core/src/main/java/org/apache/ignite/Ignition.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.jetbrains.annotations.*; +import java.io.*; import java.net.*; import java.util.*; @@ -382,6 +383,24 @@ public class Ignition { * Loads Spring bean by its name from given Spring XML configuration file. If bean * with such name doesn't exist, exception is thrown. * + * @param springXmlCfg Spring XML configuration input stream (cannot be {@code null}). + * @param beanName Bean name (cannot be {@code null}). + * @return Loaded bean instance. + * @throws IgniteException If bean with provided name was not found or in case any other error. + */ + public static T loadSpringBean(InputStream springXmlCfg, String beanName) throws IgniteException { + try { + return IgnitionEx.loadSpringBean(springXmlCfg, beanName); + } + catch (IgniteCheckedException e) { + throw U.convertException(e); + } + } + + /** + * Loads Spring bean by its name from given Spring XML configuration file. If bean + * with such name doesn't exist, exception is thrown. + * * @param springXmlUrl Spring XML configuration file URL (cannot be {@code null}). * @param beanName Bean name (cannot be {@code null}). * @return Loaded bean instance. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 56ec3ae..29182aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -916,6 +916,23 @@ public class IgnitionEx { } /** + * Loads spring bean by name. + * + * @param springXmlCfg Spring XML input stream. + * @param beanName Bean name. + * @return Bean instance. + * @throws IgniteCheckedException In case of error. + */ + public static T loadSpringBean(InputStream springXmlCfg, String beanName) throws IgniteCheckedException { + A.notNull(springXmlCfg, "springXmlUrl"); + A.notNull(beanName, "beanName"); + + IgniteSpringHelper spring = SPRING.create(false); + + return spring.loadBean(springXmlCfg, beanName); + } + + /** * Gets an instance of default no-name grid. Note that * caller of this method should not assume that it will return the same * instance every time. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java index 6bdfbac..ff47937 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelper.java @@ -22,6 +22,7 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.internal.processors.resource.*; import org.apache.ignite.lang.*; +import java.io.*; import java.net.*; import java.util.*; @@ -81,6 +82,16 @@ public interface IgniteSpringHelper { public T loadBean(URL url, String beanName) throws IgniteCheckedException; /** + * Loads bean instance by name. + * + * @param inputStream Spring XML file URL. + * @param beanName Bean name. + * @return Bean instance. + * @throws IgniteCheckedException In case of error. + */ + public T loadBean(InputStream inputStream, String beanName) throws IgniteCheckedException; + + /** * Gets user version for given class loader by checking * {@code META-INF/ignite.xml} file for {@code userVersion} attribute. If * {@code ignite.xml} file is not found, or user version is not specified there, http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartNearTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartNearTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartNearTask.java new file mode 100644 index 0000000..87c3dfa --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartNearTask.java @@ -0,0 +1,78 @@ +/* + * 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.ignite.internal.visor.cache; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.task.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.internal.visor.*; +import org.apache.ignite.lang.*; + +import java.io.*; +import java.nio.charset.*; + +/** + * Task that stop specified caches on specified node. + */ +@GridInternal +public class VisorCacheStartNearTask extends VisorOneNodeTask, Void> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override protected VisorCacheStartJob job(IgniteBiTuple arg) { + return new VisorCacheStartJob(arg, debug); + } + + /** + * Job that stop specified caches. + */ + private static class VisorCacheStartJob extends VisorJob, Void> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Create job. + * + * @param arg Contains XML configurations of cache and near cache tuple. + * @param debug Debug flag. + */ + private VisorCacheStartJob(IgniteBiTuple arg, boolean debug) { + super(arg, debug); + } + + /** {@inheritDoc} */ + @Override protected Void run(IgniteBiTuple arg) { + assert arg.get1() != null; + assert arg.get2() != null; + + NearCacheConfiguration nearCfg = Ignition.loadSpringBean( + new ByteArrayInputStream(arg.get2().getBytes(StandardCharsets.UTF_8)), "nearCacheConfiguration"); + + ignite.createNearCache(arg.get1(), nearCfg); + + return null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(VisorCacheStartJob.class, this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java new file mode 100644 index 0000000..b158ca2 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStartTask.java @@ -0,0 +1,86 @@ +/* + * 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.ignite.internal.visor.cache; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.task.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.internal.visor.*; +import org.apache.ignite.lang.*; + +import java.io.*; + +/** + * Task that stop specified caches on specified node. + */ +@GridInternal +public class VisorCacheStartTask extends VisorOneNodeTask, Void> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override protected VisorCacheStartJob job(IgniteBiTuple arg) { + return new VisorCacheStartJob(arg, debug); + } + + /** + * Job that stop specified caches. + */ + private static class VisorCacheStartJob extends VisorJob, Void> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Create job. + * + * @param arg Contains XML configurations of cache and near cache tuple. + * @param debug Debug flag. + */ + private VisorCacheStartJob(IgniteBiTuple arg, boolean debug) { + super(arg, debug); + } + + /** {@inheritDoc} */ + @Override protected Void run(IgniteBiTuple arg) { + String ccfg = arg.get1(); + + assert ccfg != null; + + CacheConfiguration cfg = Ignition.loadSpringBean( + new ByteArrayInputStream(ccfg.getBytes()), "cacheConfiguration"); + + if (!F.isEmpty(arg.get2())) { + NearCacheConfiguration nearCfg = Ignition.loadSpringBean( + new ByteArrayInputStream(arg.get2().getBytes()), "nearCacheConfiguration"); + + ignite.createCache(cfg, nearCfg); + } + else + ignite.createCache(cfg); + + return null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(VisorCacheStartJob.class, this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da04a0ec/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java index 0c69b53..ba88085 100644 --- a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java +++ b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java @@ -133,18 +133,49 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper { } } + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public T loadBean(InputStream is, String beanName) throws IgniteCheckedException { + ApplicationContext springCtx = initContext(new InputStreamResource(is)); + + try { + return (T)springCtx.getBean(beanName); + } + catch (NoSuchBeanDefinitionException e) { + throw new IgniteCheckedException("Spring bean with provided name doesn't exist [stream=" + is + + ", beanName=" + beanName + ']'); + } + catch (BeansException e) { + throw new IgniteCheckedException("Failed to load Spring bean with provided name [stream=" + is + + ", beanName=" + beanName + ']', e); + } + } + /** * @param url XML file URL. * @return Context. * @throws IgniteCheckedException In case of error. */ private ApplicationContext initContext(URL url) throws IgniteCheckedException { + return initContext(new UrlResource(url)); + } + + /** + * @param res Resource to load Spring configuration. + * @return Context. + * @throws IgniteCheckedException In case of error. + */ + private ApplicationContext initContext(Resource res) throws IgniteCheckedException { GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); - new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url)); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx); + + reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); + + reader.loadBeanDefinitions(res); springCtx.refresh(); } @@ -152,10 +183,10 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + - "[springUrl=" + url + ']', e); + "[resource=" + res + ']', e); else - throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + - url + ", err=" + e.getMessage() + ']', e); + throw new IgniteCheckedException("Failed to instantiate Spring XML application context [resource=" + + res + ", err=" + e.getMessage() + ']', e); } return springCtx;