Skip to content

Commit

Permalink
Merge pull request #40 from IBMStreams/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
petenicholls authored Feb 8, 2019
2 parents eddcd23 + 959324f commit b20cc41
Show file tree
Hide file tree
Showing 6 changed files with 456 additions and 241 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ This is the initial public release. For best results you should also install th

### Setup Instructions
#### Build - Streaming Analytics Credentials
The <b>build-ibmstreams</b> package requires a running IBM Streaming Analytics service. SPL applications will be built and deployed on this service. If you need to create one, start <a href="https://console.bluemix.net/catalog/services/streaming-analytics" rel="noopener" target="_blank">here</a> and follow the instructions to create an account.
The <b>build-ibmstreams</b> package requires a running IBM Streaming Analytics service. SPL applications will be built and deployed on this service. If you need to create one, start <a href="https://cloud.ibm.com/catalog/services/streaming-analytics" rel="noopener" target="_blank">here</a> and follow the instructions to create an account.

<b>Note:</b>The service needs to support V2 of the rest api.

Once you have an account go to your <a href="https://console.bluemix.net/dashboard/apps" rel="noopener" target="_blank">dashboard</a> and select the Streaming Analytic service you want to use. You need to make sure it is running and then copy your credentials to the clipboard. To get your credentials select <b>Service Credentials</b> from the actions on the left. From the credentials page, press <b>View credentials</b> for the one you want to use and press the copy button in the upper right side of the credentials to copy them to the clipboard.
Once you have an account go to your <a href="https://cloud.ibm.com/resources?groups=resource-instance" rel="noopener" target="_blank">dashboard</a> and select the Streaming Analytics service you want to use. You need to make sure it is running and then copy your credentials to the clipboard. To get your credentials select <b>Service Credentials</b> from the actions on the left. From the credentials page, press <b>View credentials</b> for the one you want to use and press the copy button in the upper right side of the credentials to copy them to the clipboard.

In Atom there is a setting in the <b>build-ibmstreams</b> package for the credentials. Go to <b>Atom->Preferences->Packages</b> and press the <b>Settings</b> button on the <b>build-ibmstreams</b> package and paste your credentials into the setting.
![](./images/atomcredssetting.png)


### SPL Application build
![](./images/build.gif)
![](./images/build.gif)
8 changes: 7 additions & 1 deletion lib/LintHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export class LintHandler {
location: {

file: absolutePath,
position: [[parts[2]-1,parts[3]-1],[parts[2]-1,parts[3]]], // 0-indexed
position: [
[parseInt(parts[2])-1 ,parseInt(parts[3])-1],
[parseInt(parts[2])-1,parseInt(parts[3])]
], // 0-indexed
},
excerpt: parts[4],
description: parts[5],
Expand All @@ -67,6 +70,9 @@ export class LintHandler {

this.linter.setAllMessages(convertedMessages);

if (Array.isArray(convertedMessages) && convertedMessages.length > 0) {
atom.workspace.open("atom://nuclide/diagnostics");
}
}
}
}
245 changes: 115 additions & 130 deletions lib/MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,166 +3,151 @@
"use strict";
"use babel";

import path from "path";

const packageRoot = atom.packages.resolvePackagePath("build-ibmstreams");
const STREAMING_ANALYTICS_ICON_PATH = `${packageRoot}${path.sep}assets${path.sep}streaming_analytics_200x200.png`;

export class MessageHandler {
consoleService: null;

constructor(service) {
this.consoleService = service;
}

handleBuildProgressMessage(messageOutput: Array<any> | string, showNotification?: boolean) {
if (Array.isArray(messageOutput)) {
const message = this.getLoggableMessage(messageOutput);
if (message) {
this.consoleService.log(message);
if (showNotification) {
atom.notifications.addInfo("building...", {detail: message});
}
}
} else if (typeof(messageOutput) === "string") {
this.consoleService.log(messageOutput);
if (showNotification) {
atom.notifications.addInfo(messageOutput, {});
}
handleInfo(
message,
{
detail = null,
description = null,
showNotification = true,
showConsoleMessage = true,
notificationAutoDismiss = true,
notificationButtons = []
} = {}
) {
const addedButtons = this.processButtons(notificationButtons);
const detailMessage = this.joinMessageArray(detail);

if (showConsoleMessage) {
this.consoleService.log(`${message}${detailMessage ? "\n"+detailMessage: ""}`);
}
}

handleBuildSuccess(messageOutput: Array<any>) {
const message = this.getLoggableMessage(messageOutput);
if (message) {
this.consoleService.success(message);
atom.notifications.addSuccess("Build succeeded", {detail: message, dismissable: true});
} else {
this.consoleService.success("Build succeeded");
atom.notifications.addSuccess("Build succeeded", {dismissable: true});
if (showNotification && typeof(message) === "string") {
const notificationOptions = {
...addedButtons,
dismissable: !notificationAutoDismiss,
detail: detailMessage ? detailMessage : "",
description: description ? description : ""
};
return atom.notifications.addInfo(message, notificationOptions);
}
}

handleBuildFailure(messageOutput: Array<any>) {
const message = this.getLoggableMessage(messageOutput);
if (message) {
handleError(
message,
{
detail,
description,
stack,
showNotification = true,
showConsoleMessage = true,
consoleErrorLog = true,
notificationAutoDismiss = false,
notificationButtons = []
} = {}
) {
const addedButtons = this.processButtons(notificationButtons);
const detailMessage = this.joinMessageArray(detail);
const stackMessage = this.joinMessageArray(stack);

if (consoleErrorLog) {
if (stack) {
console.error(message, stack);
} else {
console.error(message);
}
}
if (showConsoleMessage) {
this.consoleService.error(message);
atom.notifications.addError("Build failed", {detail: message, dismissable: true});
} else {
this.consoleService.error("Build failed");
atom.notifications.addError("Build failed", {dismissable: true});
if (typeof(detailMessage) === "string" && detailMessage.length > 0) {
this.consoleService.error(detailMessage);
}
}
}

handleSubmitProgressMessage(input) {
if (typeof(input) === "string") {
atom.notifications.addInfo(input, {});
if (showNotification && typeof(message) === "string") {
const notificationOptions = {
...addedButtons,
dismissable: !notificationAutoDismiss,
detail: detailMessage ? detailMessage : "",
stack: stackMessage ? stackMessage: "",
description: description ? description : ""
};
return atom.notifications.addError(message, notificationOptions);
}
this.consoleService.log(input);
}

handleSubmitSuccess(input, notificationButtons = []) {
let addedButtons = {};
if (Array.isArray(notificationButtons)) {
addedButtons.buttons = notificationButtons.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
handleSuccess(
message,
{
detail = null,
description = null,
showNotification = true,
showConsoleMessage = true,
notificationAutoDismiss = false,
notificationButtons = []
} = {}
) {
const addedButtons = this.processButtons(notificationButtons);
const detailMessage = this.joinMessageArray(detail);

if (showConsoleMessage) {
this.consoleService.log(`${message}${detailMessage ? "\n"+detailMessage: ""}`);
}
atom.notifications.addSuccess(`Job ${input.name} is ${input.health}`, {...addedButtons, dismissable: true});

if (this.consoleService) {
this.consoleService.success(`Job ${input.name} is ${input.health}`);
if (showNotification && typeof(message) === "string") {
const notificationOptions = {
...addedButtons,
dismissable: !notificationAutoDismiss,
detail: detailMessage ? detailMessage : "",
description: description ? description : ""
};
return atom.notifications.addSuccess(message, notificationOptions);
}
}

handleSubmitFailure(input) {
const errorString = input.errors.map(err => err.message).join("\n");
atom.notifications.addError(`Job submission failed`, {detail: errorString, dismissable: true});

if (this.consoleService) {
this.consoleService.error(`Job submission failed\n${errorString}`);
}
}
handleError(input, notificationButtons = []) {
let addedButtons = {};
if (Array.isArray(notificationButtons)) {
addedButtons.buttons = notificationButtons.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
}
if (typeof(input) === "string") {
atom.notifications.addError(input, {...addedButtons, dismissable: true});
this.consoleService.error(input);
} else if (input.message) {
atom.notifications.addError(
input.message,
{...addedButtons, dismissable: true, detail: input.stack, stack: input.stack}
);
this.consoleService.error(input.message);
}
console.error(input);
}
handleSuccess(input, detail, showNotification, showConsoleMsg, notificationButtons = []) {
let addedButtons = {};
if (Array.isArray(notificationButtons)) {
addedButtons.buttons = notificationButtons.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
}
if (showNotification) {
atom.notifications.addSuccess(input, {...addedButtons, detail: detail, dismissable: true});
}
if (showConsoleMsg) {
if (this.consoleService) {
this.consoleService.success(`${input}\n${detail}`);
}
}
}

handleWarning(message) {
if (message && typeof(message) === "string") {
this.consoleService.warn(message);
atom.notifications.addWarning(message, {});
}
}

showDialog(message, detail, buttonObjs) {

const nativeImage = require("electron").nativeImage;

const labels = buttonObjs.map(obj => obj.label);
const callbacks = buttonObjs.map(obj => obj.callbackFn);
let buttons = {};
labels.forEach((label, index) => {
buttons[label] = callbacks[index];
});
atom.confirm(
{
message: message,
detail: detail,
buttons: labels,
icon: STREAMING_ANALYTICS_ICON_PATH
},
(chosen, checkboxChecked) => {
const callback = callbacks[chosen];
if (typeof(callback) === "function") {
return callback();
}
}
);
}

handleCredentialsMissing() {
atom.notifications.addError(
handleCredentialsMissing(errorNotification) {
const n = atom.notifications.addError(
"Copy and paste the Streaming Analytics service credentials into the build-ibmstreams package settings page.",
{
dismissable: true,
buttons: [{
text: "Open package settings",
onDidClick: () => {atom.workspace.open("atom://config/packages/build-ibmstreams")}
onDidClick: () => {
this.dismissNotification(errorNotification);
this.dismissNotification(n);
atom.workspace.open("atom://config/packages/build-ibmstreams");
}
}]
}
);
return n;
}

processButtons(btns) {
let buttons = {};
if (Array.isArray(btns)) {
buttons.buttons = btns.map(obj => ({onDidClick: obj.callbackFn, text: obj.label}));
}
return buttons;
}

joinMessageArray(msgArray) {
if (Array.isArray(msgArray)) {
return msgArray.join("\n").trimRight();
}
return msgArray;
}

dismissNotification(notification) {
if (notification && typeof(notification.dismiss) === "function") {
notification.dismiss();
}
}

getLoggableMessage(messages: Array<any>) {
return messages
.map(outputMsg => outputMsg.message_text)
.join("\n")
.trimRight();
return this.joinMessageArray(messages.map(outputMsg => outputMsg.message_text));
}
}
Loading

0 comments on commit b20cc41

Please sign in to comment.