fix(home): fix an issue when trying to connect to an Azure ACI endpoint (#2671)

pull/2682/head
Anthony Lapenna 2019-02-04 09:04:52 +13:00 committed by GitHub
parent 2eec8b75d0
commit 899cd5f279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 120 additions and 120 deletions

View File

@ -1,139 +1,139 @@
angular.module('portainer.app') angular.module('portainer.app')
.controller('HomeController', ['$q', '$scope', '$state', 'Authentication', 'EndpointService', 'EndpointHelper', 'GroupService', 'Notifications', 'EndpointProvider', 'StateManager', 'LegacyExtensionManager', 'ModalService', 'MotdService', 'SystemService', .controller('HomeController', ['$q', '$scope', '$state', 'Authentication', 'EndpointService', 'EndpointHelper', 'GroupService', 'Notifications', 'EndpointProvider', 'StateManager', 'LegacyExtensionManager', 'ModalService', 'MotdService', 'SystemService',
function ($q, $scope, $state, Authentication, EndpointService, EndpointHelper, GroupService, Notifications, EndpointProvider, StateManager, LegacyExtensionManager, ModalService, MotdService, SystemService) { function($q, $scope, $state, Authentication, EndpointService, EndpointHelper, GroupService, Notifications, EndpointProvider, StateManager, LegacyExtensionManager, ModalService, MotdService, SystemService) {
$scope.goToEdit = function(id) { $scope.goToEdit = function(id) {
$state.go('portainer.endpoints.endpoint', { id: id }); $state.go('portainer.endpoints.endpoint', { id: id });
}; };
$scope.goToDashboard = function (endpoint) { $scope.goToDashboard = function(endpoint) {
if (endpoint.Type === 3) { if (endpoint.Type === 3) {
return switchToAzureEndpoint(endpoint); return switchToAzureEndpoint(endpoint);
} }
checkEndpointStatus(endpoint) checkEndpointStatus(endpoint)
.then(function sucess() { .then(function sucess() {
return switchToDockerEndpoint(endpoint); return switchToDockerEndpoint(endpoint);
}).catch(function error(err) { }).catch(function error(err) {
Notifications.error('Failure', err, 'Unable to verify endpoint status'); Notifications.error('Failure', err, 'Unable to verify endpoint status');
}); });
}; };
$scope.dismissImportantInformation = function (hash) { $scope.dismissImportantInformation = function(hash) {
StateManager.dismissImportantInformation(hash); StateManager.dismissImportantInformation(hash);
}; };
$scope.dismissInformationPanel = function (id) { $scope.dismissInformationPanel = function(id) {
StateManager.dismissInformationPanel(id); StateManager.dismissInformationPanel(id);
}; };
$scope.triggerSnapshot = function () { $scope.triggerSnapshot = function() {
ModalService.confirmEndpointSnapshot(function (result) { ModalService.confirmEndpointSnapshot(function(result) {
if (!result) { if (!result) {
return; return;
} }
triggerSnapshot(); triggerSnapshot();
}); });
}; };
function checkEndpointStatus(endpoint) { function checkEndpointStatus(endpoint) {
var deferred = $q.defer(); var deferred = $q.defer();
var status = 1;
SystemService.ping(endpoint.Id)
.then(function sucess() {
status = 1;
}).catch(function error() {
status = 2;
}).finally(function() {
if (endpoint.Status === status) {
deferred.resolve(endpoint);
return deferred.promise;
}
EndpointService.updateEndpoint(endpoint.Id, { Status: status })
.then(function sucess() {
deferred.resolve(endpoint);
}).catch(function error(err) {
deferred.reject({ msg: 'Unable to update endpoint status', err: err });
});
});
var status = 1;
SystemService.ping(endpoint.Id)
.then(function sucess() {
status = 1;
}).catch(function error() {
status = 2;
}).finally(function () {
if (endpoint.Status === status) {
deferred.resolve(endpoint);
return deferred.promise; return deferred.promise;
} }
EndpointService.updateEndpoint(endpoint.Id, { Status: status }) function switchToAzureEndpoint(endpoint) {
.then(function sucess() { EndpointProvider.setEndpointID(endpoint.Id);
deferred.resolve(endpoint); EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
}).catch(function error(err) { EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
deferred.reject({msg: 'Unable to update endpoint status', err: err}); StateManager.updateEndpointState(endpoint, [])
}); .then(function success() {
}); $state.go('azure.dashboard');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to connect to the Azure endpoint');
});
}
return deferred.promise; function switchToDockerEndpoint(endpoint) {
} if (endpoint.Status === 2 && endpoint.Snapshots[0] && endpoint.Snapshots[0].Swarm === true) {
Notifications.error('Failure', '', 'Endpoint is unreachable. Connect to another swarm manager.');
return;
} else if (endpoint.Status === 2 && !endpoint.Snapshots[0]) {
Notifications.error('Failure', '', 'Endpoint is unreachable and there is no snapshot available for offline browsing.');
return;
}
function switchToAzureEndpoint(endpoint) { EndpointProvider.setEndpointID(endpoint.Id);
EndpointProvider.setEndpointID(endpoint.Id); EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL); EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
EndpointProvider.setOfflineModeFromStatus(endpoint.Status); LegacyExtensionManager.initEndpointExtensions(endpoint)
StateManager.updateEndpointState(endpoint.Name, endpoint.Type, []) .then(function success(data) {
.then(function success() { var extensions = data;
$state.go('azure.dashboard'); return StateManager.updateEndpointState(endpoint, extensions);
}) })
.catch(function error(err) { .then(function success() {
Notifications.error('Failure', err, 'Unable to connect to the Azure endpoint'); $state.go('docker.dashboard');
}); })
} .catch(function error(err) {
Notifications.error('Failure', err, 'Unable to connect to the Docker endpoint');
});
}
function switchToDockerEndpoint(endpoint) { function triggerSnapshot() {
if (endpoint.Status === 2 && endpoint.Snapshots[0] && endpoint.Snapshots[0].Swarm === true) { EndpointService.snapshotEndpoints()
Notifications.error('Failure', '', 'Endpoint is unreachable. Connect to another swarm manager.'); .then(function success() {
return; Notifications.success('Success', 'Endpoints updated');
} else if (endpoint.Status === 2 && !endpoint.Snapshots[0]) { $state.reload();
Notifications.error('Failure', '', 'Endpoint is unreachable and there is no snapshot available for offline browsing.'); })
return; .catch(function error(err) {
} Notifications.error('Failure', err, 'An error occured during endpoint snapshot');
});
}
EndpointProvider.setEndpointID(endpoint.Id); function initView() {
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL); $scope.isAdmin = Authentication.getUserDetails().role === 1;
EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
LegacyExtensionManager.initEndpointExtensions(endpoint)
.then(function success(data) {
var extensions = data;
return StateManager.updateEndpointState(endpoint, extensions);
})
.then(function success() {
$state.go('docker.dashboard');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to connect to the Docker endpoint');
});
}
function triggerSnapshot() { MotdService.motd()
EndpointService.snapshotEndpoints() .then(function success(data) {
.then(function success() { $scope.motd = data;
Notifications.success('Success', 'Endpoints updated'); });
$state.reload();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'An error occured during endpoint snapshot');
});
}
function initView() { $q.all({
$scope.isAdmin = Authentication.getUserDetails().role === 1; endpoints: EndpointService.endpoints(),
groups: GroupService.groups()
})
.then(function success(data) {
var endpoints = data.endpoints;
var groups = data.groups;
EndpointHelper.mapGroupNameToEndpoint(endpoints, groups);
$scope.endpoints = endpoints;
EndpointProvider.setEndpoints(endpoints);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve endpoint information');
});
}
MotdService.motd() initView();
.then(function success(data) { }]);
$scope.motd = data;
});
$q.all({
endpoints: EndpointService.endpoints(),
groups: GroupService.groups()
})
.then(function success(data) {
var endpoints = data.endpoints;
var groups = data.groups;
EndpointHelper.mapGroupNameToEndpoint(endpoints, groups);
$scope.endpoints = endpoints;
EndpointProvider.setEndpoints(endpoints);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve endpoint information');
});
}
initView();
}]);