ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [4/4] incubator-ignite git commit: # IGNITE-843 Allow to generate full java class.
Date Sun, 28 Jun 2015 18:57:36 GMT
# IGNITE-843 Allow to generate full java class.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/3feaae21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/3feaae21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/3feaae21

Branch: refs/heads/ignite-843
Commit: 3feaae214a4b64743bfd6968136923ddd7a65baf
Parents: 9692272
Author: sevdokimov <sergey.evdokimov@jetbrains.com>
Authored: Sun Jun 28 21:57:12 2015 +0300
Committer: sevdokimov <sergey.evdokimov@jetbrains.com>
Committed: Sun Jun 28 21:57:12 2015 +0300

----------------------------------------------------------------------
 .../public/javascripts/controllers/summary.js   | 36 ++++++-------
 .../webconfig/nodejs/routes/configGenerator.js  |  2 +-
 modules/webconfig/nodejs/utils/generatorJava.js | 54 +++++++++++++++-----
 .../webconfig/nodejs/utils/generatorUtils.js    | 36 ++++++++++++-
 modules/webconfig/nodejs/views/summary.jade     | 14 +++--
 5 files changed, 103 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3feaae21/modules/webconfig/nodejs/public/javascripts/controllers/summary.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/summary.js b/modules/webconfig/nodejs/public/javascripts/controllers/summary.js
index bbb78b8..c47a999 100644
--- a/modules/webconfig/nodejs/public/javascripts/controllers/summary.js
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/summary.js
@@ -22,17 +22,22 @@ configuratorModule.controller('clustersList', ['$scope', '$http', function
($sco
         $scope.clusters = data.clusters;
     });
 
-    $scope.cfgLang = 'xml';
-
-    $scope.generateConfig = function(cluster) {
+    $scope.generateConfig = function() {
         var lang = $scope.cfgLang;
 
         if (lang == 'docker')
-            lang = 'xml';
+            return;
+
+        var cluster = $scope.currCluster;
+        
+        if (!cluster)
+            return;
         
         $scope.loading = true;
 
-        $http.get('/rest/configGenerator', {params: {name: cluster.name, lang: lang}}).success(
+        $http.get('/rest/configGenerator', {params: 
+        {name: cluster.name, lang: lang, generateJavaClass: $scope.generateJavaClass}})
+            .success(
             function (data) {
                 if (lang == 'java') {
                     $scope.resultJava = data;
@@ -49,6 +54,11 @@ configuratorModule.controller('clustersList', ['$scope', '$http', function
($sco
             });
     };
 
+    $scope.cfgLang = 'xml';
+
+    $scope.$watch('cfgLang', $scope.generateConfig);
+    $scope.$watch('generateJavaClass', $scope.generateConfig);
+
     $scope.dockerArg = {
         os: 'debian:8'
     };
@@ -113,21 +123,11 @@ configuratorModule.controller('clustersList', ['$scope', '$http', function
($sco
             "\n"+
             "RUN mv /tmp/*.xml /home/$(ls)/config";
     };
-    
-    $scope.setSelectedCluster = function(cluster) {
+
+    $scope.setSelectedCluster = function (cluster) {
         $scope.currCluster = cluster;
 
-        $scope.generateConfig(cluster)
+        $scope.generateConfig()
     };
-    
-    $scope.setCfgLang = function(lang) {
-        $scope.resultJava = '';
-        $scope.resultXml = '';
-        $scope.resultDocker = '';
-        
-        $scope.cfgLang = lang;
 
-        if ($scope.currCluster)
-            $scope.generateConfig($scope.currCluster, lang)
-    }
 }]);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3feaae21/modules/webconfig/nodejs/routes/configGenerator.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/routes/configGenerator.js b/modules/webconfig/nodejs/routes/configGenerator.js
index 0313e9c..f570962 100644
--- a/modules/webconfig/nodejs/routes/configGenerator.js
+++ b/modules/webconfig/nodejs/routes/configGenerator.js
@@ -55,7 +55,7 @@ router.get('/', function(req, res) {
                     break;
 
                 case 'java':
-                    res.send(generatorJava.generateClusterConfiguration(cluster));
+                    res.send(generatorJava.generateClusterConfiguration(cluster, req.query.generateJavaClass));
                     break;
 
                 default:

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3feaae21/modules/webconfig/nodejs/utils/generatorJava.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorJava.js b/modules/webconfig/nodejs/utils/generatorJava.js
index a1bc00a..0bbdd73 100644
--- a/modules/webconfig/nodejs/utils/generatorJava.js
+++ b/modules/webconfig/nodejs/utils/generatorJava.js
@@ -17,20 +17,29 @@
 
 var generatorUtils = require("./generatorUtils");
 
-exports.generateClusterConfiguration = function(cluster) {
+exports.generateClusterConfiguration = function(cluster, generateJavaClass) {
     var res = generatorUtils.builder();
 
+    if (generateJavaClass) {
+        res.startBlock('public class ConfigurationFactory {');
+        res.line();
+        res.startBlock('public IgniteConfiguration createConfiguration() {');
+    }
+    
+    res.importClass('org.apache.ignite.configuration.IgniteConfiguration');
+    
     res.line('IgniteConfiguration cfg = new IgniteConfiguration();');
     res.line();
 
     if (cluster.discovery) {
         var d = cluster.discovery;
 
+        res.importClass('org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi');
         res.line('TcpDiscoverySpi discovery = new TcpDiscoverySpi();');
         switch (d.kind) {
             case 'Multicast':
                 addBeanWithProperties(res, d.Multicast, 'discovery', 'ipFinder', 'ipFinder',
-                    'TcpDiscoveryMulticastIpFinder', {
+                    'org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder',
{
                         multicastGroup: null,
                         multicastPort: null,
                         responseWaitTime: null,
@@ -42,7 +51,7 @@ exports.generateClusterConfiguration = function(cluster) {
 
             case 'Vm':
                 addBeanWithProperties(res, d.Vm, 'discovery', 'ipFinder', 'ipFinder',
-                    'TcpDiscoveryVmIpFinder', {
+                    'org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder',
{
                         addresses: {type: 'list'}
                     }, true);
 
@@ -51,9 +60,12 @@ exports.generateClusterConfiguration = function(cluster) {
             case 'S3':
                 if (d.S3) {
                     addBeanWithProperties(res, d.S3, 'discovery', 'ipFinder', 'ipFinder',
-                        'TcpDiscoveryS3IpFinder', {bucketName: null}, true);
+                        'org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder',
{bucketName: null}, 
+                        true);
                 }
                 else {
+                    res.importClass('org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder');
+                    
                     res.line('discovery.setIpFinder(new TcpDiscoveryS3IpFinder());');
                 }
 
@@ -61,7 +73,7 @@ exports.generateClusterConfiguration = function(cluster) {
 
             case 'Cloud':
                 addBeanWithProperties(res, d.Cloud, 'discovery', 'ipFinder', 'ipFinder',
-                    'TcpDiscoveryCloudIpFinder', {
+                    'org.apache.ignite.spi.discovery.tcp.ipfinder.cloud.TcpDiscoveryCloudIpFinder',
{
                         credential: null,
                         credentialPath: null,
                         identity: null,
@@ -72,7 +84,7 @@ exports.generateClusterConfiguration = function(cluster) {
 
             case 'GoogleStorage':
                 addBeanWithProperties(res, d.GoogleStorage, 'discovery', 'ipFinder', 'ipFinder',
-                    'TcpDiscoveryGoogleStorageIpFinder', {
+                    'org.apache.ignite.spi.discovery.tcp.ipfinder.gce.TcpDiscoveryGoogleStorageIpFinder',
{
                         projectName: null,
                         bucketName: null,
                         serviceAccountP12FilePath: null
@@ -84,6 +96,8 @@ exports.generateClusterConfiguration = function(cluster) {
                 break;
 
             case 'Jdbc':
+                res.importClass('org.apache.ignite.spi.discovery.tcp.ipfinder.jdbc.TcpDiscoveryJdbcIpFinder');
+                
                 res.line();
                 res.line('TcpDiscoveryJdbcIpFinder ipFinder = new TcpDiscoveryJdbcIpFinder();');
                 res.line('ipFinder.setInitSchema(' + (d.Jdbc.initSchema != null || d.Jdbc.initSchema)
+ ');');
@@ -94,7 +108,8 @@ exports.generateClusterConfiguration = function(cluster) {
 
             case 'SharedFs':
                 addBeanWithProperties(res, d.SharedFs, 'discovery', 'ipFinder', 'ipFinder',
-                    'TcpDiscoverySharedFsIpFinder', {path: null}, true);
+                    'org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinder',
{path: null}, 
+                    true);
 
                 break;
 
@@ -146,7 +161,7 @@ exports.generateClusterConfiguration = function(cluster) {
     }
 
     addBeanWithProperties(res, cluster.atomicConfiguration, 'cfg', 'atomicConfiguration',
'atomicCfg',
-        generatorUtils.atomicConfiguration.shortClassName, generatorUtils.atomicConfiguration.fields);
+        generatorUtils.atomicConfiguration.className, generatorUtils.atomicConfiguration.fields);
 
     res.needEmptyLine = true;
 
@@ -167,6 +182,8 @@ exports.generateClusterConfiguration = function(cluster) {
         res.emptyLineIfNeeded();
         
         if (cluster.includeEventTypes.length == 1) {
+            res.importClass('org.apache.ignite.events.EventType');
+            
             res.line('cfg.setIncludeEventTypes(EventType.' + cluster.includeEventTypes[0]
+ ');');
         }
         else {
@@ -220,7 +237,7 @@ exports.generateClusterConfiguration = function(cluster) {
 
     if (cluster.swapSpaceSpi && cluster.swapSpaceSpi.kind == 'FileSwapSpaceSpi')
{
         addBeanWithProperties(res, cluster.swapSpaceSpi.FileSwapSpaceSpi, 'cfg', 'swapSpaceSpi',
'swapSpi',
-            generatorUtils.swapSpaceSpi.shortClassName, generatorUtils.swapSpaceSpi.fields,
true);
+            generatorUtils.swapSpaceSpi.className, generatorUtils.swapSpaceSpi.fields, true);
 
         res.needEmptyLine = true;
     }
@@ -240,7 +257,7 @@ exports.generateClusterConfiguration = function(cluster) {
     res.needEmptyLine = true;
 
     addBeanWithProperties(res, cluster.transactionConfiguration, 'cfg', 'transactionConfiguration',
-        'transactionConfiguration', generatorUtils.transactionConfiguration.shortClassName,
+        'transactionConfiguration', generatorUtils.transactionConfiguration.className,
         generatorUtils.transactionConfiguration.fields);
 
     res.needEmptyLine = true;
@@ -259,6 +276,14 @@ exports.generateClusterConfiguration = function(cluster) {
     addProperty(res, cluster, 'cfg', 'utilityCacheKeepAliveTime');
     addProperty(res, cluster, 'cfg', 'utilityCachePoolSize');
 
+    if (generateJavaClass) {
+        res.line('return cfg;');
+        res.endBlock('}');
+        res.endBlock('}');
+        
+        return res.generateImports() + '\n\n' + res.join('')
+    }
+    
     return res.join('');
 };
 
@@ -268,7 +293,7 @@ function createEvictionPolicy(res, evictionPolicy, varName, propertyName)
{
 
         var obj = evictionPolicy[evictionPolicy.kind.toUpperCase()];
 
-        addBeanWithProperties(res, obj, varName, propertyName, propertyName, e.shortClassName,
e.fields, true);
+        addBeanWithProperties(res, obj, varName, propertyName, propertyName, e.className,
e.fields, true);
     }
 }
 
@@ -280,6 +305,8 @@ function generateCacheConfiguration(cacheCfg, varName, res) {
 
     res.emptyLineIfNeeded();
 
+    res.importClass('org.apache.ignite.configuration.CacheConfiguration');
+    
     res.line('CacheConfiguration ' + varName + ' = new CacheConfiguration();');
 
     res.needEmptyLine = true;
@@ -304,7 +331,8 @@ function generateCacheConfiguration(cacheCfg, varName, res) {
     res.needEmptyLine = true;
     
     addBeanWithProperties(res, cacheCfg.nearConfiguration, varName, 'nearConfiguration',
'nearConfiguration',
-        'NearCacheConfiguration', {nearStartSize: null, atomicSequenceReserveSize: null},
true);
+        'org.apache.ignite.configuration.NearCacheConfiguration', 
+        {nearStartSize: null, atomicSequenceReserveSize: null}, true);
     
     if (cacheCfg.nearConfiguration && cacheCfg.nearConfiguration.nearEvictionPolicy
&& cacheCfg.nearConfiguration.nearEvictionPolicy.kind) {
         createEvictionPolicy(res, cacheCfg.nearConfiguration.nearEvictionPolicy, 'nearConfiguration',
'nearEvictionPolicy');
@@ -351,7 +379,7 @@ function generateCacheConfiguration(cacheCfg, varName, res) {
         var obj = cacheCfg.cacheStoreFactory[cacheCfg.cacheStoreFactory.kind];
         var data = generatorUtils.storeFactories[cacheCfg.cacheStoreFactory.kind];
 
-        addBeanWithProperties(res, obj, varName, 'cacheStoreFactory', 'cacheStoreFactory',
data.shortClassName,
+        addBeanWithProperties(res, obj, varName, 'cacheStoreFactory', 'cacheStoreFactory',
data.className,
             data.fields, true);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3feaae21/modules/webconfig/nodejs/utils/generatorUtils.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorUtils.js b/modules/webconfig/nodejs/utils/generatorUtils.js
index b987917..80f612a 100644
--- a/modules/webconfig/nodejs/utils/generatorUtils.js
+++ b/modules/webconfig/nodejs/utils/generatorUtils.js
@@ -101,14 +101,46 @@ exports.builder = function () {
         return false;
     };
 
+    res.imports = {};
+    
+    res.importClass = function(fullClassName) {
+        var dotIdx = fullClassName.lastIndexOf('.');
+        
+        var shortName;
+        
+        if (dotIdx > 0)
+            shortName = fullClassName.substr(dotIdx + 1);
+        else 
+            shortName = fullClassName;
+        
+        if (this.imports[shortName]) {
+            if (this.imports[shortName] != fullClassName)
+                throw "Class name conflict: " + this.imports[shortName] + ' and ' + fullClassName;
+        }
+        else {
+            this.imports[shortName] = fullClassName;
+        }
+        
+        return shortName;
+    };
+    
+    res.generateImports = function() {
+        var res = [];
+        
+        for (var clsName in this.imports) {
+            if (this.imports.hasOwnProperty(clsName))
+                res.push('import ' + this.imports[clsName] + ';');
+        }
+        
+        return res.join('\n')
+    };
+    
     return res;
 };
 
 function ClassDescriptor(className, fields) {
     this.className = className;
 
-    this.shortClassName = className.substr(className.lastIndexOf('.') + 1);
-
     this.fields = fields;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3feaae21/modules/webconfig/nodejs/views/summary.jade
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/views/summary.jade b/modules/webconfig/nodejs/views/summary.jade
index 369d539..5388191 100644
--- a/modules/webconfig/nodejs/views/summary.jade
+++ b/modules/webconfig/nodejs/views/summary.jade
@@ -40,12 +40,12 @@ block content
 
             #cfgResult.configBox(ng-show='currCluster && !generateError &&
!loading', style='margin-top: 20px')
                 ul.nav.nav-tabs
-                    li(ng-class="{active: cfgLang=='xml'}")
-                        a(href, ng-click='setCfgLang("xml")') XML
-                    li(ng-class="{active: cfgLang=='java'}")
-                        a(href, ng-click='setCfgLang("java")') Java
+                    li(ng-class='{active: cfgLang=="xml"}')
+                        a(href, ng-click='cfgLang = "xml"') XML
+                    li(ng-class='{active: cfgLang=="java"}')
+                        a(href, ng-click='cfgLang = "java"') Java
                     li(ng-class="{active: cfgLang=='docker'}")
-                        a(href, ng-click='setCfgLang("docker")') Dockerfile
+                        a(href, ng-click='cfgLang = "docker"') Dockerfile
 
                 div(style='padding-top: 10px')        
                     #xmlResult(ng-show="cfgLang == 'xml'")
@@ -53,6 +53,10 @@ block content
                             | {{resultXml}}
                 
                     #javaResult(ng-show="cfgLang == 'java'")
+                        label
+                            input(type='checkbox', ng-model="generateJavaClass")
+                            | generate java class.
+                        
                         textarea.form-control(rows=30, readonly=true)
                             | {{resultJava}}
                     


Mime
View raw message