2015-10-07 07:06:09 -04:00
|
|
|
/*
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
solrAdminApp.controller('CollectionsController',
|
|
|
|
function($scope, $routeParams, $location, $timeout, Collections, Zookeeper, Constants){
|
|
|
|
$scope.resetMenu("collections", Constants.IS_ROOT_PAGE);
|
|
|
|
|
|
|
|
$scope.refresh = function() {
|
|
|
|
|
2015-10-23 05:08:04 -04:00
|
|
|
$scope.rootUrl = Constants.ROOT_URL + "#/~collections/" + $routeParams.collection;
|
|
|
|
|
2015-10-07 07:06:09 -04:00
|
|
|
Collections.status(function (data) {
|
|
|
|
$scope.collections = [];
|
|
|
|
for (var name in data.cluster.collections) {
|
|
|
|
var collection = data.cluster.collections[name];
|
|
|
|
collection.name = name;
|
2019-08-30 08:16:58 -04:00
|
|
|
collection.type = 'collection';
|
2015-10-07 07:06:09 -04:00
|
|
|
var shards = collection.shards;
|
|
|
|
collection.shards = [];
|
|
|
|
for (var shardName in shards) {
|
|
|
|
var shard = shards[shardName];
|
|
|
|
shard.name = shardName;
|
|
|
|
shard.collection = collection.name;
|
|
|
|
var replicas = shard.replicas;
|
|
|
|
shard.replicas = [];
|
|
|
|
for (var replicaName in replicas) {
|
|
|
|
var replica = replicas[replicaName];
|
|
|
|
replica.name = replicaName;
|
|
|
|
replica.collection = collection.name;
|
|
|
|
replica.shard = shard.name;
|
|
|
|
shard.replicas.push(replica);
|
|
|
|
}
|
|
|
|
collection.shards.push(shard);
|
|
|
|
}
|
|
|
|
$scope.collections.push(collection);
|
|
|
|
if ($routeParams.collection == name) {
|
|
|
|
$scope.collection = collection;
|
|
|
|
}
|
|
|
|
}
|
2019-08-30 08:16:58 -04:00
|
|
|
// Fetch aliases using LISTALIASES to get properties
|
|
|
|
Collections.listaliases(function (adata) {
|
|
|
|
// TODO: Population of aliases array duplicated in app.js
|
|
|
|
$scope.aliases = [];
|
|
|
|
for (var key in adata.aliases) {
|
|
|
|
props = {};
|
|
|
|
if (key in adata.properties) {
|
|
|
|
props = adata.properties[key];
|
|
|
|
}
|
|
|
|
var alias = {name: key, collections: adata.aliases[key], type: 'alias', properties: props};
|
|
|
|
$scope.aliases.push(alias);
|
|
|
|
if ($routeParams.collection == 'alias_' + key) {
|
|
|
|
$scope.collection = alias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Decide what is selected in list
|
|
|
|
if ($routeParams.collection && !$scope.collection) {
|
|
|
|
alert("No collection or alias called " + $routeParams.collection);
|
|
|
|
$location.path("/~collections");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-07 07:06:09 -04:00
|
|
|
$scope.liveNodes = data.cluster.liveNodes;
|
|
|
|
});
|
|
|
|
Zookeeper.configs(function(data) {
|
|
|
|
$scope.configs = [];
|
|
|
|
var items = data.tree[0].children;
|
|
|
|
for (var i in items) {
|
2020-01-23 15:13:29 -05:00
|
|
|
$scope.configs.push({name: items[i].text});
|
2015-10-07 07:06:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.hideAll = function() {
|
|
|
|
$scope.showRename = false;
|
|
|
|
$scope.showAdd = false;
|
|
|
|
$scope.showDelete = false;
|
|
|
|
$scope.showSwap = false;
|
|
|
|
$scope.showCreateAlias = false;
|
|
|
|
$scope.showDeleteAlias = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showAddCollection = function() {
|
|
|
|
$scope.hideAll();
|
|
|
|
$scope.showAdd = true;
|
|
|
|
$scope.newCollection = {
|
2015-10-20 21:53:51 -04:00
|
|
|
name: "",
|
2015-10-07 07:06:09 -04:00
|
|
|
routerName: "compositeId",
|
|
|
|
numShards: 1,
|
|
|
|
configName: "",
|
2020-07-20 08:17:01 -04:00
|
|
|
replicationFactor: 1
|
2015-10-07 07:06:09 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleCreateAlias = function() {
|
|
|
|
$scope.hideAll();
|
|
|
|
$scope.showCreateAlias = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.toggleDeleteAlias = function() {
|
|
|
|
$scope.hideAll();
|
|
|
|
$scope.showDeleteAlias = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.cancelCreateAlias = $scope.cancelDeleteAlias = function() {
|
|
|
|
$scope.hideAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.createAlias = function() {
|
2016-08-15 21:15:37 -04:00
|
|
|
var collections = [];
|
|
|
|
for (var i in $scope.aliasCollections) {
|
|
|
|
collections.push($scope.aliasCollections[i].name);
|
|
|
|
}
|
|
|
|
Collections.createAlias({name: $scope.aliasToCreate, collections: collections.join(",")}, function(data) {
|
2019-08-30 08:16:58 -04:00
|
|
|
$scope.cancelCreateAlias();
|
|
|
|
$scope.resetMenu("collections", Constants.IS_ROOT_PAGE);
|
|
|
|
$location.path("/~collections/alias_" + $scope.aliasToCreate);
|
2015-10-07 07:06:09 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
$scope.deleteAlias = function() {
|
2019-08-30 08:16:58 -04:00
|
|
|
Collections.deleteAlias({name: $scope.collection.name}, function(data) {
|
2015-10-07 07:06:09 -04:00
|
|
|
$scope.hideAll();
|
2019-08-30 08:16:58 -04:00
|
|
|
$scope.resetMenu("collections", Constants.IS_ROOT_PAGE);
|
|
|
|
$location.path("/~collections/");
|
2015-10-07 07:06:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
$scope.addCollection = function() {
|
|
|
|
if (!$scope.newCollection.name) {
|
|
|
|
$scope.addMessage = "Please provide a core name";
|
|
|
|
} else if (false) { //@todo detect whether core exists
|
|
|
|
$scope.AddMessage = "A core with that name already exists";
|
|
|
|
} else {
|
|
|
|
var coll = $scope.newCollection;
|
|
|
|
var params = {
|
|
|
|
name: coll.name,
|
|
|
|
"router.name": coll.routerName,
|
|
|
|
numShards: coll.numShards,
|
|
|
|
"collection.configName": coll.configName,
|
2020-07-20 08:17:01 -04:00
|
|
|
replicationFactor: coll.replicationFactor
|
2015-10-07 07:06:09 -04:00
|
|
|
};
|
|
|
|
if (coll.shards) params.shards = coll.shards;
|
2018-03-02 12:42:43 -05:00
|
|
|
if (coll.routerField) params["router.field"] = coll.routerField;
|
2015-10-07 07:06:09 -04:00
|
|
|
Collections.add(params, function(data) {
|
|
|
|
$scope.cancelAddCollection();
|
|
|
|
$scope.resetMenu("collections", Constants.IS_ROOT_PAGE);
|
|
|
|
$location.path("/~collections/" + $scope.newCollection.name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancelAddCollection = function() {
|
|
|
|
delete $scope.addMessage;
|
|
|
|
$scope.showAdd = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showDeleteCollection = function() {
|
|
|
|
$scope.hideAll();
|
|
|
|
if ($scope.collection) {
|
|
|
|
$scope.showDelete = true;
|
|
|
|
} else {
|
|
|
|
alert("No collection selected.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteCollection = function() {
|
|
|
|
if ($scope.collection.name == $scope.collectionDeleteConfirm) {
|
|
|
|
Collections.delete({name: $scope.collection.name}, function (data) {
|
|
|
|
$location.path("/~collections");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$scope.deleteMessage = "Collection names do not match.";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.reloadCollection = function() {
|
|
|
|
if (!$scope.collection) {
|
|
|
|
alert("No collection selected.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Collections.reload({name: $scope.collection.name},
|
|
|
|
function(successData) {
|
|
|
|
$scope.reloadSuccess = true;
|
|
|
|
$timeout(function() {$scope.reloadSuccess=false}, 1000);
|
|
|
|
},
|
|
|
|
function(failureData) {
|
|
|
|
$scope.reloadFailure = true;
|
|
|
|
$timeout(function() {$scope.reloadFailure=false}, 1000);
|
|
|
|
$location.path("/~collections");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleAddReplica = function(shard) {
|
|
|
|
$scope.hideAll();
|
|
|
|
shard.showAdd = !shard.showAdd;
|
|
|
|
delete $scope.addReplicaMessage;
|
|
|
|
|
|
|
|
Zookeeper.liveNodes({}, function(data) {
|
|
|
|
$scope.nodes = [];
|
|
|
|
var children = data.tree[0].children;
|
|
|
|
for (var child in children) {
|
2020-10-15 14:36:31 -04:00
|
|
|
$scope.nodes.push(children[child].text);
|
2015-10-07 07:06:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleRemoveReplica = function(replica) {
|
|
|
|
$scope.hideAll();
|
|
|
|
replica.showRemove = !replica.showRemove;
|
|
|
|
};
|
2020-10-15 14:36:31 -04:00
|
|
|
|
2017-03-04 18:04:49 -05:00
|
|
|
$scope.toggleRemoveShard = function(shard) {
|
|
|
|
$scope.hideAll();
|
|
|
|
shard.showRemove = !shard.showRemove;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteShard = function(shard) {
|
|
|
|
Collections.deleteShard({collection: shard.collection, shard:shard.name}, function(data) {
|
|
|
|
shard.deleted = true;
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.refresh();
|
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
}
|
2015-10-07 07:06:09 -04:00
|
|
|
|
|
|
|
$scope.deleteReplica = function(replica) {
|
|
|
|
Collections.deleteReplica({collection: replica.collection, shard:replica.shard, replica:replica.name}, function(data) {
|
|
|
|
replica.deleted = true;
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.refresh();
|
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$scope.addReplica = function(shard) {
|
|
|
|
var params = {
|
|
|
|
collection: shard.collection,
|
|
|
|
shard: shard.name,
|
2020-10-16 11:01:48 -04:00
|
|
|
type: shard.replicaType
|
2015-10-07 07:06:09 -04:00
|
|
|
}
|
|
|
|
if (shard.replicaNodeName && shard.replicaNodeName != "") {
|
|
|
|
params.node = shard.replicaNodeName;
|
|
|
|
}
|
|
|
|
Collections.addReplica(params, function(data) {
|
|
|
|
shard.replicaAdded = true;
|
|
|
|
$timeout(function () {
|
|
|
|
shard.replicaAdded = false;
|
|
|
|
shard.showAdd = false;
|
2020-10-15 14:36:31 -04:00
|
|
|
$scope.refresh();
|
2015-10-07 07:06:09 -04:00
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleShard = function(shard) {
|
|
|
|
shard.show = !shard.show;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.toggleReplica = function(replica) {
|
|
|
|
replica.show = !replica.show;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.refresh();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
var flatten = function(data) {
|
|
|
|
var list = [];
|
|
|
|
for (var name in data) {
|
|
|
|
var entry = data[name];
|
|
|
|
entry.name = name;
|
|
|
|
list.push(entry);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|