Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Update delivery-logs build 'result' #402

Merged
merged 3 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ <h3 translate>You have not set up a delivery pipeline</h3>
</dd>
</dl>
</div>
<!--st-pipe="appDelLogsCtrl.updateDisplayed"-->
<div id="delivery-logs"
st-table="appDelLogsCtrl.displayedExecutions"
st-safe-src="appDelLogsCtrl.parsedHceModel.pipelineExecutions"
Expand Down Expand Up @@ -96,8 +95,12 @@ <h3 translate>You have not set up a delivery pipeline</h3>
<span ng-switch-default class="helion-icon helion-icon-Active_S"></span>
</div>
<span translate>{{ execution.result.label }}</span>
<a translate ng-if="execution.result.artifact_id"
ng-click="appDelLogsCtrl.viewEventForExecution(execution)">view</a>
<a translate
ng-if="execution.result.state === appDelLogsCtrl.eventStates.SUCCEEDED &&
appCtrl.model.application.summary.routes[0]"
target="_blank"
ng-init="route=appCtrl.model.application.summary.routes[0]"
ng-href="http://{{ route.host + '.' + route.domain.name + (route.port ? ':' + route.port : '') + '/' + route.path }}">view</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe route.path will already have a slash pre-pended so you don't need to add it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a restriction enforced by HCF, or they check and prepend? Was wondering if we ever get the state where we show an app created outside the console where there is no slash. Two slashes aren't valid but I think most browser will accept them. Either way, happy to remove if you wish?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, according to CF's API documentation, the path or route has to be start with slash. the api doc is at http://apidocs.cloudfoundry.org/237/routes/check_a_route_exists.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, ok. Slash removed in latest commit

</td>
<td>{{ execution.reason.createdDate | amDateFormat:'L - LTS' }}</td>
<td>{{ execution.reason.author }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@
});
},

viewEventForExecution: function(execution) {
var events = this.eventsPerExecution[execution.id];

if (!events || events.length === 0) {
return;
}

this.viewEvent(events[events.length - 1]);
},

viewEvent: function(event) {
this.detailView({
templateUrl: 'plugins/cloud-foundry/view/applications/application/delivery-logs/details/event.html',
Expand Down Expand Up @@ -349,28 +339,32 @@

var event = events[events.length - 1];

execution.result = {
state: this.determineExecutionState(event),
label: event.name,
hasLog: event.artifact_id
};
execution.result = this.determineExecutionResult(event);
},

/**
* @name ApplicationDeliveryLogsController.determineExecutionState
* @description Determines the execution state from the last received event
* @name ApplicationDeliveryLogsController.determineExecutionResult
* @description Determines the execution result from the last received event
* @param {object} event - Last HCE event of an execution
* @returns {string} - Updated execution state
* @returns {object} - Content required by UX to display the execution result
*/
determineExecutionState: function(event) {
if (
determineExecutionResult: function(event) {
var hasCompleted =
event.type === this.eventTypes.PIPELINE_COMPLETED ||
event.type === this.eventTypes.WATCHDOG_TERMINATED ||
event.state === this.eventStates.FAILED) {
return event.state;
} else {
return this.eventStates.RUNNING;
event.state === this.eventStates.FAILED;

var result = {
state: hasCompleted ? event.state : this.eventStates.RUNNING,
label: event.name
};

// Override the label for this specific case. This is the real 'result' of the execution
if (event.type === this.eventTypes.PIPELINE_COMPLETED) {
result.label = event.state === this.eventStates.SUCCEEDED ? gettext('Success') : gettext('Failed');
}

return result;
},

updateVisibleExecutions: function(visibleExecutions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,55 +289,6 @@
});
});

describe('View Event for execution', function() {
var execution = {
id: 'two'
};

beforeEach(function() {
createController(true);
_.set(controller, 'hceCnsi.guid', cnsi.guid);
});

it('Without events', function() {
_.set(controller, 'eventsPerExecution', {});

spyOn(controller, 'viewEvent');

controller.viewEventForExecution(execution);
$rootScope.$apply();

expect(controller.viewEvent).not.toHaveBeenCalled();
});

it('With events', function() {
var event = {
event: '1',
name: 'name'
};
var events = [ event ];
_.set(controller, 'eventsPerExecution', {
one: [
{
event: '1'
},
{
event: '2'
}
],
two: events
});

spyOn(controller, 'viewEvent');

controller.viewEventForExecution(execution);
$rootScope.$apply();

expect(controller.viewEvent).toHaveBeenCalled();
expect(controller.viewEvent.calls.argsFor(0)[0]).toEqual(event);
});
});

describe('Fetching events', function() {

var event1 = {
Expand Down Expand Up @@ -583,6 +534,56 @@
});
});

describe('determine execution result', function() {

beforeEach(function() {
createController(true);
});

it('execution completed (pipeline_complete - failed)', function() {
var event = {
type: controller.eventTypes.PIPELINE_COMPLETED,
state: controller.eventStates.FAILED,
name: 'label'
};
var res = controller.determineExecutionResult(event);
expect(res.label).toEqual('Failed');
expect(res.state).toEqual(event.state);
});

it('execution completed (pipeline_complete - success)', function() {
var event = {
type: controller.eventTypes.PIPELINE_COMPLETED,
state: controller.eventStates.SUCCEEDED,
name: 'label'
};
var res = controller.determineExecutionResult(event);
expect(res.label).toEqual('Success');
expect(res.state).toEqual(event.state);
});

it('execution completed (failed event)', function() {
var event = {
type: controller.eventTypes.TESTING,
state: controller.eventStates.FAILED,
name: 'label'
};
var res = controller.determineExecutionResult(event);
expect(res.label).toEqual(event.name);
expect(res.state).toEqual(event.state);
});

it('execution still running', function() {
var event = {
type: controller.eventTypes.TESTING,
name: 'label'
};
var res = controller.determineExecutionResult(event);
expect(res.label).toEqual(event.name);
expect(res.state).toEqual(controller.eventStates.RUNNING);
});
});

describe('determine execution state', function() {
beforeEach(function() {
createController(true);
Expand Down