Compare commits

...

3 Commits

Author SHA1 Message Date
Chaim Lev-Ari
113e58f916 feat(stack): filter endpoints for migration 2021-05-03 08:22:19 +03:00
Chaim Lev-Ari
76e2790918 refactor(endpoints): allow droping query params for endpoint 2021-05-03 08:16:14 +03:00
Chaim Lev-Ari
0dab9d25cd feat(endpoints): filter endpoints by a list of types 2021-05-03 08:16:14 +03:00
5 changed files with 41 additions and 21 deletions

View File

@@ -46,7 +46,9 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
groupID, _ := request.RetrieveNumericQueryParameter(r, "groupId", true)
limit, _ := request.RetrieveNumericQueryParameter(r, "limit", true)
endpointType, _ := request.RetrieveNumericQueryParameter(r, "type", true)
var endpointTypes []int
request.RetrieveJSONQueryParameter(r, "types", &endpointTypes, true)
var tagIDs []portainer.TagID
request.RetrieveJSONQueryParameter(r, "tagIds", &tagIDs, true)
@@ -98,8 +100,8 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
filteredEndpoints = filterEndpointsBySearchCriteria(filteredEndpoints, endpointGroups, tagsMap, search)
}
if endpointType != 0 {
filteredEndpoints = filterEndpointsByType(filteredEndpoints, portainer.EndpointType(endpointType))
if endpointTypes != nil {
filteredEndpoints = filterEndpointsByTypes(filteredEndpoints, endpointTypes)
}
if tagIDs != nil {
@@ -212,11 +214,16 @@ func endpointGroupMatchSearchCriteria(endpoint *portainer.Endpoint, endpointGrou
return false
}
func filterEndpointsByType(endpoints []portainer.Endpoint, endpointType portainer.EndpointType) []portainer.Endpoint {
func filterEndpointsByTypes(endpoints []portainer.Endpoint, endpointTypes []int) []portainer.Endpoint {
filteredEndpoints := make([]portainer.Endpoint, 0)
typeSet := map[portainer.EndpointType]bool{}
for _, endpointType := range endpointTypes {
typeSet[portainer.EndpointType(endpointType)] = true
}
for _, endpoint := range endpoints {
if endpoint.Type == endpointType {
if typeSet[endpoint.Type] {
filteredEndpoints = append(filteredEndpoints, endpoint)
}
}

View File

@@ -95,7 +95,7 @@ export class EditEdgeStackViewController {
async getPaginatedEndpointsAsync(lastId, limit, search) {
try {
const query = { search, type: 4, endpointIds: this.stackEndpointIds };
const query = { search, types: [4], endpointIds: this.stackEndpointIds };
const { value, totalCount } = await this.EndpointService.endpoints(lastId, limit, query);
const endpoints = _.map(value, (endpoint) => {
const status = this.stack.Status[endpoint.Id];

View File

@@ -56,7 +56,7 @@ class AssoicatedEndpointsSelectorController {
async getEndpointsAsync() {
const { start, search, limit } = this.getPaginationData('available');
const query = { search, type: 4 };
const query = { search, types: [4] };
const response = await this.EndpointService.endpoints(start, limit, query);
@@ -73,7 +73,7 @@ class AssoicatedEndpointsSelectorController {
let response = { value: [], totalCount: 0 };
if (this.endpointIds.length > 0) {
const { start, search, limit } = this.getPaginationData('associated');
const query = { search, type: 4, endpointIds: this.endpointIds };
const query = { search, types: [4], endpointIds: this.endpointIds };
response = await this.EndpointService.endpoints(start, limit, query);
}

View File

@@ -14,11 +14,19 @@ angular.module('portainer.app').factory('EndpointService', [
return Endpoints.get({ id: endpointID }).$promise;
};
service.endpoints = function (start, limit, { search, type, tagIds, endpointIds, tagsPartialMatch } = {}) {
service.endpoints = function (start, limit, query = {}) {
if (typeof start === 'object') {
query = start;
start = undefined;
limit = undefined;
}
const { search, types, tagIds, endpointIds, tagsPartialMatch } = query;
if (tagIds && !tagIds.length) {
return Promise.resolve({ value: [], totalCount: 0 });
}
return Endpoints.query({ start, limit, search, type, tagIds: JSON.stringify(tagIds), endpointIds: JSON.stringify(endpointIds), tagsPartialMatch }).$promise;
return Endpoints.query({ start, limit, search, types: JSON.stringify(types), tagIds: JSON.stringify(tagIds), endpointIds: JSON.stringify(endpointIds), tagsPartialMatch })
.$promise;
};
service.snapshotEndpoints = function () {

View File

@@ -20,6 +20,7 @@ angular.module('portainer.app').controller('StackController', [
'ModalService',
'StackHelper',
'ContainerHelper',
'endpoint',
function (
$async,
$q,
@@ -41,7 +42,8 @@ angular.module('portainer.app').controller('StackController', [
GroupService,
ModalService,
StackHelper,
ContainerHelper
ContainerHelper,
endpoint
) {
$scope.state = {
actionInProgress: false,
@@ -249,16 +251,20 @@ angular.module('portainer.app').controller('StackController', [
$scope.state.actionInProgress = false;
}
function loadStack(id) {
function isEndpointSwarm(endpoint) {
return endpoint.Snapshots.length ? endpoint.Snapshots[0].Swarm : false;
}
async function loadStack(id) {
var agentProxy = $scope.applicationState.endpoint.mode.agentProxy;
EndpointService.endpoints()
.then(function success(data) {
$scope.endpoints = data.value;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve endpoints');
});
try {
const isSwarm = isEndpointSwarm(endpoint);
const endpointsResponse = await EndpointService.endpoints({ types: [1, 2, 3] });
$scope.endpoints = endpointsResponse.value.filter((endpoint) => isSwarm === isEndpointSwarm(endpoint));
} catch (err) {
Notifications.error('Failure', err, 'Unable to retrieve endpoints');
}
$q.all({
stack: StackService.stack(id),
@@ -394,7 +400,7 @@ angular.module('portainer.app').controller('StackController', [
var stackName = $transition$.params().name;
$scope.stackName = stackName;
var external = $transition$.params().external;
$scope.currentEndpointId = EndpointProvider.endpointID();
$scope.currentEndpointId = endpoint.Id;
if (external === 'true') {
$scope.state.externalStack = true;
@@ -405,7 +411,6 @@ angular.module('portainer.app').controller('StackController', [
}
try {
const endpoint = EndpointProvider.currentEndpoint();
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
} catch (err) {
Notifications.error('Failure', err, 'Unable to retrieve the ComposeSyntaxMaxVersion');