Skip to content

Commit

Permalink
Stream Deploy Edit
Browse files Browse the repository at this point in the history
Resolves #625
  • Loading branch information
oodamien committed May 4, 2018
1 parent 55a202c commit 306cdc0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
6 changes: 4 additions & 2 deletions ui/src/app/streams/stream-deploy/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export class StreamDeployBuilderComponent implements OnInit, OnDestroy {
if (appNames.indexOf(appKey) > -1) {
const appProperties = builder.streamDeployConfig.apps[appNames.indexOf(appKey)];
if (appProperties.options && !appProperties.optionsState.isInvalid) {
const option = builder.builderAppsProperties[appKey].find(opt => opt.name === keyReduce);
const option = builder.builderAppsProperties[appKey].find(opt => {
return opt.name === keyReduce || opt.id === keyReduce;
});
if (option) {
option.value = value;
free = false;
Expand Down Expand Up @@ -502,7 +504,7 @@ export class StreamDeployBuilderComponent implements OnInit, OnDestroy {
}
return appProperties.map((property: Properties.Property) => {
return (property.value !== undefined && property.value.toString() !== '' && property.value !== property.defaultValue) ? ({
key: `${property.name}`,
key: `${property.id}`,
value: property.value
}) : null;
}).filter((app) => app !== null);
Expand Down
61 changes: 58 additions & 3 deletions ui/src/app/streams/stream-deploy/stream-deploy.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { StreamsService } from '../streams.service';
import { Subject } from 'rxjs/Subject';
import { ToastyService } from 'ng2-toasty';
import { BusyService } from '../../shared/services/busy.service';
import { StreamDefinition } from '../model/stream-definition';
import { Parser } from '../../shared/services/parser';
import { StreamDeployService } from './stream-deploy.service';

/**
* Component used to deploy stream definitions.
Expand Down Expand Up @@ -89,6 +92,51 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
};
}
))
.pipe(mergeMap(
val => this.streamsService.getDeploymentInfo(val.id),
(config: any, deploymentInfo: StreamDefinition) => {
const properties = [];

// Deployer properties
Object.keys(deploymentInfo.deploymentProperties).map(app => {
Object.keys(deploymentInfo.deploymentProperties[app]).forEach((key: string) => {
const value = deploymentInfo.deploymentProperties[app][key];
if (key === StreamDeployService.version.keyEdit) {
properties.push(`version.${app}=${value}`);
} else if (key.startsWith(StreamDeployService.deployer.keyEdit)) {
const keyShort = key.substring(StreamDeployService.deployer.keyEdit.length, key.length);
if (keyShort !== 'group') {
properties.push(`deployer.${app}.${keyShort}=${value}`);
} else {
console.log(`${key} is bypassed (app: ${app}, value: ${value})`);
}
} else {
console.log(`${key} is bypassed (app: ${app}, value: ${value})`);
}
});
});

// Application properties
const dslTextParsed = Parser.parse(deploymentInfo.dslText, 'stream');
dslTextParsed.lines[0].nodes.forEach((node) => {
const app = node['label'] || node['name'];
const appType = node['name'];
if (node['options']) {
node.options.forEach((value, key) => {
let keyShort = key;
if (key.startsWith(`${appType}.`)) {
keyShort = key.substring(`${appType}.`.length, key.length);
}
properties.push(`app.${app}.${keyShort}=${value}`);
});
}
});

this.properties = properties;
config.streamDefinition = deploymentInfo;
return config;
}
))
.pipe(map((config) => {
this.refConfig = config;
return config;
Expand Down Expand Up @@ -140,21 +188,28 @@ export class StreamDeployComponent implements OnInit, OnDestroy {
propertiesMap[arr[0]] = arr[1];
}
});
const busy = this.streamsService.deployDefinition(this.refConfig.id, propertiesMap)

let obs = Observable.of({});
if (['deployed', 'deploying'].indexOf(this.refConfig.streamDefinition.status) > -1) {
obs = this.streamsService.undeployDefinition(this.refConfig.streamDefinition);
}
const busy = obs.pipe(mergeMap(
val => this.streamsService.deployDefinition(this.refConfig.id, propertiesMap),
(val1, val2) => val2
))
.pipe(takeUntil(this.ngUnsubscribe$))
.subscribe(
data => {
this.toastyService.success(`Successfully deployed stream definition "${this.refConfig.id}"`);
this.router.navigate(['streams']);
},
error => {
console.log(error);
console.log(error.message);
this.toastyService.error(`${error.message ? error.message : error.toString()}`);
}
);

this.busyService.addSubscription(busy);

}

}
14 changes: 12 additions & 2 deletions ui/src/app/streams/stream-deploy/stream-deploy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ export class StreamDeployService {
* Deployer key validation
*/
public static deployer = {
keyEdit: 'spring.cloud.deployer.',
is: (key: string): boolean => {
return /^(deployer.)/.test(key);
},
extract: (key: string): string => {
const result = key.split('.');
return result.length > 2 ? result[2] : '';
if (result.length < 3) {
return '';
}
return result.slice(2, result.length)
.join('.');
},
};

/**
* Version key validation
*/
public static version = {
keyEdit: 'version',
is: (key: string): boolean => {
return /^(version.)/.test(key);
}
Expand All @@ -63,7 +69,11 @@ export class StreamDeployService {
},
extract: (key: string): string => {
const result = key.split('.');
return result.length > 2 ? result[2] : '';
if (result.length < 3) {
return '';
}
return result.slice(2, result.length)
.join('.');
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
Undeploy
</button>
<button name="stream-deploy" type="button" [appRoles]="['ROLE_CREATE']"
[disabled]="(stream.streamDefinition.status === 'deployed'
|| stream.streamDefinition.status==='deploying')" (click)="deploy(stream.streamDefinition)"
(click)="deploy(stream.streamDefinition)"
class="btn btn-default" style="margin-left: 0;" title="Deploy">
<span class="glyphicon glyphicon-play"></span>
Deploy
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/streams/streams/streams.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ <h1 class="no-user-selection">Streams</h1>
<span class="glyphicon glyphicon-stop"></span>
</button>
<button name="stream-deploy{{ i }}" type="button" [appRoles]="['ROLE_CREATE']"
[disabled]="(item.status==='deployed' || item.status==='deploying')" (click)="deploy(item)"
[disabled]="(item.status==='deploying')" (click)="deploy(item)"
class="btn btn-default" style="margin-left: 0;" title="Deploy">
<span class="glyphicon glyphicon-play"></span>
</button>
Expand Down

0 comments on commit 306cdc0

Please sign in to comment.