Skip to content

Commit

Permalink
Fetch CreateEnsembleOptions schema at runtime and remove fabric depen…
Browse files Browse the repository at this point in the history
…dency from hawtio-web's build
  • Loading branch information
gashcrumb committed Aug 28, 2013
1 parent 419b51a commit 807b92e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 47 deletions.
13 changes: 0 additions & 13 deletions hawtio-web/pom.xml
Expand Up @@ -412,9 +412,6 @@
</executions>
<configuration>
<classes>
<org.fusesource.fabric.api.CreateEnsembleOptions>
${schema-outdir}/createEnsembleOptions.js
</org.fusesource.fabric.api.CreateEnsembleOptions>
<io.hawt.dozer.schema.Mappings>
${schema-outdir}/dozerMappings.js
</io.hawt.dozer.schema.Mappings>
Expand All @@ -430,16 +427,6 @@
</classes>
</configuration>
<dependencies>
<dependency>
<groupId>org.fusesource.fabric</groupId>
<artifactId>fabric-core</artifactId>
<version>${fabric-version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.fabric</groupId>
<artifactId>fabric-api</artifactId>
<version>${fabric-version}</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-dozer-schemagen</artifactId>
Expand Down
5 changes: 4 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/createFabric.ts
Expand Up @@ -8,7 +8,10 @@ module Fabric {
}
});

$scope.schema = Fabric.createEnsembleOptions;
Fabric.getSchema('createEnsemble', 'org.fusesource.fabric.api.CreateEnsembleOptions', jolokia, (schema) => {
$scope.schema = schema;
Core.$apply($scope);
});

$scope.entity = {
zooKeeperServerPort: 2181,
Expand Down
2 changes: 0 additions & 2 deletions hawtio-web/src/main/webapp/app/fabric/js/fabricPlugin.ts
Expand Up @@ -29,8 +29,6 @@ module Fabric {

run(($location: ng.ILocationService, workspace: Workspace, jolokia, viewRegistry, pageTitle:Core.PageTitle) => {

Fabric.schemaConfigure();

viewRegistry['fabric'] = templatePath + 'layoutFabric.html';

pageTitle.addTitleElement( ():string => {
Expand Down
1 change: 1 addition & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/helpers.ts
Expand Up @@ -357,6 +357,7 @@ module Fabric {

export function getSchema(id, className, jolokia, cb) {
jolokia.execute('io.hawt.jsonschema:type=SchemaLookup', 'getSchemaForClass(java.lang.String)', className, {
method: 'POST',
success: (value) => {
cb(Fabric.customizeSchema(id, angular.fromJson(value)));
}
Expand Down
57 changes: 26 additions & 31 deletions hawtio-web/src/main/webapp/app/fabric/js/schemaConfigure.ts
Expand Up @@ -2,6 +2,8 @@ module Fabric {

export function customizeSchema(id, schema) {

console.log("Schema: ", schema);

Core.pathSet(schema, ["properties", "name", "required"], true);

delete schema.properties['metadataMap'];
Expand Down Expand Up @@ -39,6 +41,7 @@ module Fabric {
'Default': ['name', 'parent', 'jmxUser', 'jmxPassword', 'saveJmxCredentials', 'number', '*']
};
break;

case 'ssh':
delete schema.properties['parent'];

Expand All @@ -47,6 +50,7 @@ module Fabric {
'Default': ['name', 'host', 'port', 'userName', 'password', 'privateKeyFile', 'passPhrase', '*']
};
break;

case 'jcloud':
delete schema.properties['parent'];

Expand All @@ -55,6 +59,28 @@ module Fabric {
'Default': ['name', 'owner', 'credential', 'imageId', 'hardwareId', 'locationId', 'number', '*']
};
break;

case 'createEnsemble':
delete schema['properties']['name'];
angular.forEach(["username", "password", "role"], (name) => {
Core.pathSet(schema, ["properties", name, "type"], 'string');
Core.pathSet(schema, ["properties", name, "required"], true);
});

setGlobalResolverEnum(schema);
setResolverEnum(schema);

Core.pathSet(schema, ["properties", "profiles", "type"], "hidden");
Core.pathSet(schema, ['properties', 'password', 'type'], "password");
Core.pathSet(schema, ['properties', 'zookeeperPassword', 'type'], "password");

delete schema['properties']['users'];

schema['tabs'] = {
'Basic': ['username', 'password', 'role', 'zookeeperPassword', 'zooKeeperServerPort', 'globalResolver', 'resolver', 'manualIp'],
'Advanced': ['*']
};

default:
}

Expand All @@ -68,8 +94,6 @@ module Fabric {
})
}

export var createEnsembleOptions = (<any>window).org_fusesource_fabric_api_CreateEnsembleOptions;

function setGlobalResolverEnum(schema) {
var globalResolverEnum = ['localip', 'localhostname', 'publicip', 'publichostname'];
Core.pathSet(schema, ['properties', 'globalResolver', 'enum'], globalResolverEnum);
Expand All @@ -80,33 +104,4 @@ module Fabric {
Core.pathSet(schema, ['properties', 'resolver', 'enum'], resolverEnum);
}


function configureResolverSchema() {
setGlobalResolverEnum(createEnsembleOptions);
setResolverEnum(createEnsembleOptions);
}

/**
* Configures the JSON schemas to improve the UI models
*/
export function schemaConfigure() {

angular.forEach(["username", "password", "role"], (name) => {
Core.pathSet(Fabric.createEnsembleOptions, ["properties", name, "type"], 'string');
Core.pathSet(Fabric.createEnsembleOptions, ["properties", name, "required"], true);
});

configureResolverSchema();

Core.pathSet(Fabric.createEnsembleOptions, ["properties", "profiles", "type"], "hidden");
Core.pathSet(Fabric.createEnsembleOptions, ['properties', 'password', 'type'], "password");
Core.pathSet(Fabric.createEnsembleOptions, ['properties', 'zookeeperPassword', 'type'], "password");
delete Fabric.createEnsembleOptions['properties']['users'];

Fabric.createEnsembleOptions['tabs'] = {
'Basic': ['username', 'password', 'role', 'zookeeperPassword', 'zooKeeperServerPort', 'globalResolver', 'resolver', 'manualIp'],
'Advanced': ['*']
};

}
}

0 comments on commit 807b92e

Please sign in to comment.