88 changed files with 2272 additions and 291 deletions
@ -0,0 +1,22 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
public interface HasName { |
|||
|
|||
String getName(); |
|||
|
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.common.data.relation; |
|||
|
|||
public class EntityRelationInfo extends EntityRelation { |
|||
|
|||
private static final long serialVersionUID = 2807343097519543363L; |
|||
|
|||
private String toName; |
|||
|
|||
public EntityRelationInfo() { |
|||
super(); |
|||
} |
|||
|
|||
public EntityRelationInfo(EntityRelation entityRelation) { |
|||
super(entityRelation); |
|||
} |
|||
|
|||
public String getToName() { |
|||
return toName; |
|||
} |
|||
|
|||
public void setToName(String toName) { |
|||
this.toName = toName; |
|||
} |
|||
|
|||
@Override |
|||
public boolean equals(Object o) { |
|||
if (this == o) return true; |
|||
if (o == null || getClass() != o.getClass()) return false; |
|||
if (!super.equals(o)) return false; |
|||
|
|||
EntityRelationInfo that = (EntityRelationInfo) o; |
|||
|
|||
return toName != null ? toName.equals(that.toName) : that.toName == null; |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public int hashCode() { |
|||
int result = super.hashCode(); |
|||
result = 31 * result + (toName != null ? toName.hashCode() : 0); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.dao.entity; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.dao.relation.RelationService; |
|||
|
|||
@Slf4j |
|||
public abstract class AbstractEntityService { |
|||
|
|||
@Autowired |
|||
protected RelationService relationService; |
|||
|
|||
protected void deleteEntityRelations(EntityId entityId) { |
|||
log.trace("Executing deleteEntityRelations [{}]", entityId); |
|||
relationService.deleteEntityRelations(entityId); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.dao.entity; |
|||
|
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
|
|||
public interface EntityService { |
|||
|
|||
ListenableFuture<String> fetchEntityNameAsync(EntityId entityId); |
|||
|
|||
void deleteEntityRelations(EntityId entityId); |
|||
|
|||
} |
|||
@ -1 +1,7 @@ |
|||
CASSANDRA_DATA_DIR=/home/docker/cassandra_volume |
|||
|
|||
# cassandra schema container environment variables |
|||
CREATE_SCHEMA=true |
|||
ADD_SYSTEM_DATA=false |
|||
ADD_DEMO_DATA=false |
|||
CASSANDRA_URL=cassandra |
|||
@ -0,0 +1,132 @@ |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: cassandra-headless |
|||
labels: |
|||
app: cassandra-headless |
|||
spec: |
|||
ports: |
|||
- port: 9042 |
|||
name: cql |
|||
clusterIP: None |
|||
selector: |
|||
app: cassandra |
|||
--- |
|||
apiVersion: "apps/v1beta1" |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: cassandra |
|||
spec: |
|||
serviceName: cassandra-headless |
|||
replicas: 2 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: cassandra |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: other |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- cassandra-headless |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: cassandra |
|||
image: cassandra:3.9 |
|||
imagePullPolicy: Always |
|||
ports: |
|||
- containerPort: 7000 |
|||
name: intra-node |
|||
- containerPort: 7001 |
|||
name: tls-intra-node |
|||
- containerPort: 7199 |
|||
name: jmx |
|||
- containerPort: 9042 |
|||
name: cql |
|||
- containerPort: 9160 |
|||
name: thrift |
|||
securityContext: |
|||
capabilities: |
|||
add: |
|||
- IPC_LOCK |
|||
lifecycle: |
|||
preStop: |
|||
exec: |
|||
command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"] |
|||
env: |
|||
- name: MAX_HEAP_SIZE |
|||
value: 2048M |
|||
- name: HEAP_NEWSIZE |
|||
value: 100M |
|||
- name: CASSANDRA_SEEDS |
|||
value: "cassandra-0.cassandra-headless.default.svc.cluster.local" |
|||
- name: CASSANDRA_CLUSTER_NAME |
|||
value: "Thingsboard-Cluster" |
|||
- name: CASSANDRA_DC |
|||
value: "DC1-Thingsboard-Cluster" |
|||
- name: CASSANDRA_RACK |
|||
value: "Rack-Thingsboard-Cluster" |
|||
- name: CASSANDRA_AUTO_BOOTSTRAP |
|||
value: "false" |
|||
- name: POD_IP |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: status.podIP |
|||
- name: POD_NAMESPACE |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: metadata.namespace |
|||
readinessProbe: |
|||
exec: |
|||
command: |
|||
- /bin/bash |
|||
- -c |
|||
- /ready-probe.sh |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
volumeMounts: |
|||
- name: cassandra-data |
|||
mountPath: /var/lib/cassandra/data |
|||
- name: cassandra-commitlog |
|||
mountPath: /var/lib/cassandra/commitlog |
|||
volumeClaimTemplates: |
|||
- metadata: |
|||
name: cassandra-data |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: fast |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 3Gi |
|||
- metadata: |
|||
name: cassandra-commitlog |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: fast |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 2Gi |
|||
@ -0,0 +1,13 @@ |
|||
VERSION=1.2.4 |
|||
PROJECT=thingsboard |
|||
APP=tb-cassandra-schema |
|||
|
|||
build: |
|||
cp ../../dao/src/main/resources/schema.cql . |
|||
cp ../../dao/src/main/resources/demo-data.cql . |
|||
cp ../../dao/src/main/resources/system-data.cql . |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
rm schema.cql demo-data.cql system-data.cql |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -1,6 +1,7 @@ |
|||
#Thingsboard server configuration |
|||
|
|||
CASSANDRA_URL=db:9042 |
|||
TB_CASSANDRA_SCHEMA_URL=tb-cassandra-schema |
|||
CASSANDRA_URL=cassandra:9042 |
|||
ZOOKEEPER_URL=zk:2181 |
|||
MQTT_BIND_ADDRESS=0.0.0.0 |
|||
MQTT_BIND_PORT=1883 |
|||
@ -0,0 +1,11 @@ |
|||
VERSION=1.2.4 |
|||
PROJECT=thingsboard |
|||
APP=application |
|||
|
|||
build: |
|||
cp ../../application/target/thingsboard.deb . |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
rm thingsboard.deb |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,121 @@ |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
--- |
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: tb-service |
|||
labels: |
|||
app: tb-service |
|||
spec: |
|||
ports: |
|||
- port: 8080 |
|||
name: ui |
|||
- port: 1883 |
|||
name: mqtt |
|||
- port: 5683 |
|||
name: coap |
|||
selector: |
|||
app: tb |
|||
type: LoadBalancer |
|||
--- |
|||
apiVersion: policy/v1beta1 |
|||
kind: PodDisruptionBudget |
|||
metadata: |
|||
name: tb-budget |
|||
spec: |
|||
selector: |
|||
matchLabels: |
|||
app: tb |
|||
minAvailable: 3 |
|||
--- |
|||
apiVersion: v1 |
|||
kind: ConfigMap |
|||
metadata: |
|||
name: tb-config |
|||
data: |
|||
zookeeper.enabled: "true" |
|||
zookeeper.url: "zk-headless" |
|||
cassandra.url: "cassandra-headless:9042" |
|||
--- |
|||
apiVersion: apps/v1beta1 |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: tb |
|||
spec: |
|||
serviceName: "tb-service" |
|||
replicas: 3 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: tb |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: tb |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- tb-service |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: tb |
|||
imagePullPolicy: Always |
|||
image: thingsboard/application:1.2.4 |
|||
ports: |
|||
- containerPort: 8080 |
|||
name: ui |
|||
- containerPort: 1883 |
|||
name: mqtt |
|||
- containerPort: 5683 |
|||
name: coap |
|||
- containerPort: 9001 |
|||
name: rpc |
|||
env: |
|||
- name: ZOOKEEPER_ENABLED |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: zookeeper.enabled |
|||
- name: ZOOKEEPER_URL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: zookeeper.url |
|||
- name : CASSANDRA_URL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: cassandra.url |
|||
- name : RPC_HOST |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: status.podIP |
|||
command: |
|||
- sh |
|||
- -c |
|||
- ./run-application.sh |
|||
livenessProbe: |
|||
httpGet: |
|||
path: /login |
|||
port: ui-port |
|||
initialDelaySeconds: 120 |
|||
timeoutSeconds: 10 |
|||
@ -1,5 +0,0 @@ |
|||
#Db schema configuration |
|||
|
|||
SKIP_SCHEMA_CREATION=false |
|||
SKIP_SYSTEM_DATA=false |
|||
SKIP_DEMO_DATA=false |
|||
@ -1,28 +0,0 @@ |
|||
#!/bin/bash |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
|
|||
cp ../../dao/src/main/resources/schema.cql schema.cql |
|||
cp ../../dao/src/main/resources/demo-data.cql demo-data.cql |
|||
cp ../../dao/src/main/resources/system-data.cql system-data.cql |
|||
|
|||
docker build -t thingsboard/thingsboard-db-schema:1.2.3 -t thingsboard/thingsboard-db-schema:latest . |
|||
|
|||
docker login |
|||
|
|||
docker push thingsboard/thingsboard-db-schema:1.2.3 |
|||
docker push thingsboard/thingsboard-db-schema:latest |
|||
@ -1,26 +0,0 @@ |
|||
#!/bin/bash |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
|
|||
cp ../../application/target/thingsboard.deb thingsboard.deb |
|||
|
|||
docker build -t thingsboard/application:1.2.3 -t thingsboard/application:latest . |
|||
|
|||
docker login |
|||
|
|||
docker push thingsboard/application:1.2.3 |
|||
docker push thingsboard/application:latest |
|||
@ -0,0 +1,71 @@ |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
FROM ubuntu:16.04 |
|||
ENV ZK_USER=zookeeper \ |
|||
ZK_DATA_DIR=/var/lib/zookeeper/data \ |
|||
ZK_DATA_LOG_DIR=/var/lib/zookeeper/log \ |
|||
ZK_LOG_DIR=/var/log/zookeeper \ |
|||
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 |
|||
|
|||
ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D |
|||
ARG ZK_DIST=zookeeper-3.4.9 |
|||
RUN set -x \ |
|||
&& apt-get update \ |
|||
&& apt-get install -y openjdk-8-jre-headless wget netcat-openbsd \ |
|||
&& wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz" \ |
|||
&& wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz.asc" \ |
|||
&& export GNUPGHOME="$(mktemp -d)" \ |
|||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \ |
|||
&& gpg --batch --verify "$ZK_DIST.tar.gz.asc" "$ZK_DIST.tar.gz" \ |
|||
&& tar -xzf "$ZK_DIST.tar.gz" -C /opt \ |
|||
&& rm -r "$GNUPGHOME" "$ZK_DIST.tar.gz" "$ZK_DIST.tar.gz.asc" \ |
|||
&& ln -s /opt/$ZK_DIST /opt/zookeeper \ |
|||
&& rm -rf /opt/zookeeper/CHANGES.txt \ |
|||
/opt/zookeeper/README.txt \ |
|||
/opt/zookeeper/NOTICE.txt \ |
|||
/opt/zookeeper/CHANGES.txt \ |
|||
/opt/zookeeper/README_packaging.txt \ |
|||
/opt/zookeeper/build.xml \ |
|||
/opt/zookeeper/config \ |
|||
/opt/zookeeper/contrib \ |
|||
/opt/zookeeper/dist-maven \ |
|||
/opt/zookeeper/docs \ |
|||
/opt/zookeeper/ivy.xml \ |
|||
/opt/zookeeper/ivysettings.xml \ |
|||
/opt/zookeeper/recipes \ |
|||
/opt/zookeeper/src \ |
|||
/opt/zookeeper/$ZK_DIST.jar.asc \ |
|||
/opt/zookeeper/$ZK_DIST.jar.md5 \ |
|||
/opt/zookeeper/$ZK_DIST.jar.sha1 \ |
|||
&& apt-get autoremove -y wget \ |
|||
&& rm -rf /var/lib/apt/lists/* |
|||
|
|||
#Copy configuration generator script to bin |
|||
COPY zk-gen-config.sh zk-ok.sh /opt/zookeeper/bin/ |
|||
|
|||
# Create a user for the zookeeper process and configure file system ownership |
|||
# for nessecary directories and symlink the distribution as a user executable |
|||
RUN set -x \ |
|||
&& useradd $ZK_USER \ |
|||
&& [ `id -u $ZK_USER` -eq 1000 ] \ |
|||
&& [ `id -g $ZK_USER` -eq 1000 ] \ |
|||
&& mkdir -p $ZK_DATA_DIR $ZK_DATA_LOG_DIR $ZK_LOG_DIR /usr/share/zookeeper /tmp/zookeeper /usr/etc/ \ |
|||
&& chown -R "$ZK_USER:$ZK_USER" /opt/$ZK_DIST $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper \ |
|||
&& ln -s /opt/zookeeper/conf/ /usr/etc/zookeeper \ |
|||
&& ln -s /opt/zookeeper/bin/* /usr/bin \ |
|||
&& ln -s /opt/zookeeper/$ZK_DIST.jar /usr/share/zookeeper/ \ |
|||
&& ln -s /opt/zookeeper/lib/* /usr/share/zookeeper |
|||
@ -0,0 +1,9 @@ |
|||
VERSION=1.2.4 |
|||
PROJECT=thingsboard |
|||
APP=zk |
|||
|
|||
build: |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,153 @@ |
|||
#!/usr/bin/env bash |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
ZK_USER=${ZK_USER:-"zookeeper"} |
|||
ZK_LOG_LEVEL=${ZK_LOG_LEVEL:-"INFO"} |
|||
ZK_DATA_DIR=${ZK_DATA_DIR:-"/var/lib/zookeeper/data"} |
|||
ZK_DATA_LOG_DIR=${ZK_DATA_LOG_DIR:-"/var/lib/zookeeper/log"} |
|||
ZK_LOG_DIR=${ZK_LOG_DIR:-"var/log/zookeeper"} |
|||
ZK_CONF_DIR=${ZK_CONF_DIR:-"/opt/zookeeper/conf"} |
|||
ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181} |
|||
ZK_SERVER_PORT=${ZK_SERVER_PORT:-2888} |
|||
ZK_ELECTION_PORT=${ZK_ELECTION_PORT:-3888} |
|||
ZK_TICK_TIME=${ZK_TICK_TIME:-2000} |
|||
ZK_INIT_LIMIT=${ZK_INIT_LIMIT:-10} |
|||
ZK_SYNC_LIMIT=${ZK_SYNC_LIMIT:-5} |
|||
ZK_HEAP_SIZE=${ZK_HEAP_SIZE:-2G} |
|||
ZK_MAX_CLIENT_CNXNS=${ZK_MAX_CLIENT_CNXNS:-60} |
|||
ZK_MIN_SESSION_TIMEOUT=${ZK_MIN_SESSION_TIMEOUT:- $((ZK_TICK_TIME*2))} |
|||
ZK_MAX_SESSION_TIMEOUT=${ZK_MAX_SESSION_TIMEOUT:- $((ZK_TICK_TIME*20))} |
|||
ZK_SNAP_RETAIN_COUNT=${ZK_SNAP_RETAIN_COUNT:-3} |
|||
ZK_PURGE_INTERVAL=${ZK_PURGE_INTERVAL:-0} |
|||
ID_FILE="$ZK_DATA_DIR/myid" |
|||
ZK_CONFIG_FILE="$ZK_CONF_DIR/zoo.cfg" |
|||
LOGGER_PROPS_FILE="$ZK_CONF_DIR/log4j.properties" |
|||
JAVA_ENV_FILE="$ZK_CONF_DIR/java.env" |
|||
HOST=`hostname -s` |
|||
DOMAIN=`hostname -d` |
|||
|
|||
function print_servers() { |
|||
for (( i=1; i<=$ZK_REPLICAS; i++ )) |
|||
do |
|||
echo "server.$i=$NAME-$((i-1)).$DOMAIN:$ZK_SERVER_PORT:$ZK_ELECTION_PORT" |
|||
done |
|||
} |
|||
|
|||
function validate_env() { |
|||
echo "Validating environment" |
|||
if [ -z $ZK_REPLICAS ]; then |
|||
echo "ZK_REPLICAS is a mandatory environment variable" |
|||
exit 1 |
|||
fi |
|||
|
|||
if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then |
|||
NAME=${BASH_REMATCH[1]} |
|||
ORD=${BASH_REMATCH[2]} |
|||
else |
|||
echo "Failed to extract ordinal from hostname $HOST" |
|||
exit 1 |
|||
fi |
|||
MY_ID=$((ORD+1)) |
|||
echo "ZK_REPLICAS=$ZK_REPLICAS" |
|||
echo "MY_ID=$MY_ID" |
|||
echo "ZK_LOG_LEVEL=$ZK_LOG_LEVEL" |
|||
echo "ZK_DATA_DIR=$ZK_DATA_DIR" |
|||
echo "ZK_DATA_LOG_DIR=$ZK_DATA_LOG_DIR" |
|||
echo "ZK_LOG_DIR=$ZK_LOG_DIR" |
|||
echo "ZK_CLIENT_PORT=$ZK_CLIENT_PORT" |
|||
echo "ZK_SERVER_PORT=$ZK_SERVER_PORT" |
|||
echo "ZK_ELECTION_PORT=$ZK_ELECTION_PORT" |
|||
echo "ZK_TICK_TIME=$ZK_TICK_TIME" |
|||
echo "ZK_INIT_LIMIT=$ZK_INIT_LIMIT" |
|||
echo "ZK_SYNC_LIMIT=$ZK_SYNC_LIMIT" |
|||
echo "ZK_MAX_CLIENT_CNXNS=$ZK_MAX_CLIENT_CNXNS" |
|||
echo "ZK_MIN_SESSION_TIMEOUT=$ZK_MIN_SESSION_TIMEOUT" |
|||
echo "ZK_MAX_SESSION_TIMEOUT=$ZK_MAX_SESSION_TIMEOUT" |
|||
echo "ZK_HEAP_SIZE=$ZK_HEAP_SIZE" |
|||
echo "ZK_SNAP_RETAIN_COUNT=$ZK_SNAP_RETAIN_COUNT" |
|||
echo "ZK_PURGE_INTERVAL=$ZK_PURGE_INTERVAL" |
|||
echo "ENSEMBLE" |
|||
print_servers |
|||
echo "Environment validation successful" |
|||
} |
|||
|
|||
function create_config() { |
|||
rm -f $ZK_CONFIG_FILE |
|||
echo "Creating ZooKeeper configuration" |
|||
echo "#This file was autogenerated by zk DO NOT EDIT" >> $ZK_CONFIG_FILE |
|||
echo "clientPort=$ZK_CLIENT_PORT" >> $ZK_CONFIG_FILE |
|||
echo "dataDir=$ZK_DATA_DIR" >> $ZK_CONFIG_FILE |
|||
echo "dataLogDir=$ZK_DATA_LOG_DIR" >> $ZK_CONFIG_FILE |
|||
echo "tickTime=$ZK_TICK_TIME" >> $ZK_CONFIG_FILE |
|||
echo "initLimit=$ZK_INIT_LIMIT" >> $ZK_CONFIG_FILE |
|||
echo "syncLimit=$ZK_SYNC_LIMIT" >> $ZK_CONFIG_FILE |
|||
echo "maxClientCnxns=$ZK_MAX_CLIENT_CNXNS" >> $ZK_CONFIG_FILE |
|||
echo "minSessionTimeout=$ZK_MIN_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE |
|||
echo "maxSessionTimeout=$ZK_MAX_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE |
|||
echo "autopurge.snapRetainCount=$ZK_SNAP_RETAIN_COUNT" >> $ZK_CONFIG_FILE |
|||
echo "autopurge.purgeInteval=$ZK_PURGE_INTERVAL" >> $ZK_CONFIG_FILE |
|||
|
|||
if [ $ZK_REPLICAS -gt 1 ]; then |
|||
print_servers >> $ZK_CONFIG_FILE |
|||
fi |
|||
echo "Wrote ZooKeeper configuration file to $ZK_CONFIG_FILE" |
|||
} |
|||
|
|||
function create_data_dirs() { |
|||
echo "Creating ZooKeeper data directories and setting permissions" |
|||
if [ ! -d $ZK_DATA_DIR ]; then |
|||
mkdir -p $ZK_DATA_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_DATA_DIR |
|||
fi |
|||
|
|||
if [ ! -d $ZK_DATA_LOG_DIR ]; then |
|||
mkdir -p $ZK_DATA_LOG_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_DATA_LOG_DIR |
|||
fi |
|||
|
|||
if [ ! -d $ZK_LOG_DIR ]; then |
|||
mkdir -p $ZK_LOG_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_LOG_DIR |
|||
fi |
|||
if [ ! -f $ID_FILE ]; then |
|||
echo $MY_ID >> $ID_FILE |
|||
fi |
|||
echo "Created ZooKeeper data directories and set permissions in $ZK_DATA_DIR" |
|||
} |
|||
|
|||
function create_log_props () { |
|||
rm -f $LOGGER_PROPS_FILE |
|||
echo "Creating ZooKeeper log4j configuration" |
|||
echo "zookeeper.root.logger=CONSOLE" >> $LOGGER_PROPS_FILE |
|||
echo "zookeeper.console.threshold="$ZK_LOG_LEVEL >> $LOGGER_PROPS_FILE |
|||
echo "log4j.rootLogger=\${zookeeper.root.logger}" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n" >> $LOGGER_PROPS_FILE |
|||
echo "Wrote log4j configuration to $LOGGER_PROPS_FILE" |
|||
} |
|||
|
|||
function create_java_env() { |
|||
rm -f $JAVA_ENV_FILE |
|||
echo "Creating JVM configuration file" |
|||
echo "ZOO_LOG_DIR=$ZK_LOG_DIR" >> $JAVA_ENV_FILE |
|||
echo "JVMFLAGS=\"-Xmx$ZK_HEAP_SIZE -Xms$ZK_HEAP_SIZE\"" >> $JAVA_ENV_FILE |
|||
echo "Wrote JVM configuration to $JAVA_ENV_FILE" |
|||
} |
|||
|
|||
validate_env && create_config && create_log_props && create_data_dirs && create_java_env |
|||
@ -0,0 +1,190 @@ |
|||
# |
|||
# Copyright © 2016-2017 The Thingsboard Authors |
|||
# |
|||
# Licensed 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. |
|||
# |
|||
|
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: zk-headless |
|||
labels: |
|||
app: zk-headless |
|||
spec: |
|||
ports: |
|||
- port: 2888 |
|||
name: server |
|||
- port: 3888 |
|||
name: leader-election |
|||
clusterIP: None |
|||
selector: |
|||
app: zk |
|||
--- |
|||
apiVersion: v1 |
|||
kind: ConfigMap |
|||
metadata: |
|||
name: zk-config |
|||
data: |
|||
ensemble: "zk-0;zk-1;zk-2" |
|||
replicas: "3" |
|||
jvm.heap: "500m" |
|||
tick: "2000" |
|||
init: "10" |
|||
sync: "5" |
|||
client.cnxns: "60" |
|||
snap.retain: "3" |
|||
purge.interval: "1" |
|||
client.port: "2181" |
|||
server.port: "2888" |
|||
election.port: "3888" |
|||
--- |
|||
apiVersion: policy/v1beta1 |
|||
kind: PodDisruptionBudget |
|||
metadata: |
|||
name: zk-budget |
|||
spec: |
|||
selector: |
|||
matchLabels: |
|||
app: zk |
|||
minAvailable: 3 |
|||
--- |
|||
apiVersion: apps/v1beta1 |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: zk |
|||
spec: |
|||
serviceName: zk-headless |
|||
replicas: 3 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: zk |
|||
annotations: |
|||
pod.alpha.kubernetes.io/initialized: "true" |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: other |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- zk-headless |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: zk |
|||
imagePullPolicy: Always |
|||
image: thingsboard/zk:1.2.4 |
|||
ports: |
|||
- containerPort: 2181 |
|||
name: client |
|||
- containerPort: 2888 |
|||
name: server |
|||
- containerPort: 3888 |
|||
name: leader-election |
|||
env: |
|||
- name : ZK_ENSEMBLE |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: ensemble |
|||
- name : ZK_REPLICAS |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: replicas |
|||
- name : ZK_HEAP_SIZE |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: jvm.heap |
|||
- name : ZK_TICK_TIME |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: tick |
|||
- name : ZK_INIT_LIMIT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: init |
|||
- name : ZK_SYNC_LIMIT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: tick |
|||
- name : ZK_MAX_CLIENT_CNXNS |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: client.cnxns |
|||
- name: ZK_SNAP_RETAIN_COUNT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: snap.retain |
|||
- name: ZK_PURGE_INTERVAL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: purge.interval |
|||
- name: ZK_CLIENT_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: client.port |
|||
- name: ZK_SERVER_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: server.port |
|||
- name: ZK_ELECTION_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: election.port |
|||
command: |
|||
- sh |
|||
- -c |
|||
- zk-gen-config.sh && zkServer.sh start-foreground |
|||
readinessProbe: |
|||
exec: |
|||
command: |
|||
- "zk-ok.sh" |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
livenessProbe: |
|||
exec: |
|||
command: |
|||
- "zk-ok.sh" |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
volumeMounts: |
|||
- name: zkdatadir |
|||
mountPath: /var/lib/zookeeper |
|||
securityContext: |
|||
runAsUser: 1000 |
|||
fsGroup: 1000 |
|||
volumeClaimTemplates: |
|||
- metadata: |
|||
name: zkdatadir |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: slow |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 1Gi |
|||
@ -0,0 +1,171 @@ |
|||
/* |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
import './entity-autocomplete.scss'; |
|||
|
|||
/* eslint-disable import/no-unresolved, import/default */ |
|||
|
|||
import entityAutocompleteTemplate from './entity-autocomplete.tpl.html'; |
|||
|
|||
/* eslint-enable import/no-unresolved, import/default */ |
|||
|
|||
/*@ngInject*/ |
|||
export default function EntityAutocomplete($compile, $templateCache, $q, $filter, entityService, types) { |
|||
|
|||
var linker = function (scope, element, attrs, ngModelCtrl) { |
|||
var template = $templateCache.get(entityAutocompleteTemplate); |
|||
element.html(template); |
|||
|
|||
scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false; |
|||
scope.entity = null; |
|||
scope.entitySearchText = ''; |
|||
|
|||
scope.fetchEntities = function(searchText) { |
|||
var deferred = $q.defer(); |
|||
entityService.getEntitiesByNameFilter(scope.entityType, searchText, 50, null, scope.entitySubtype).then(function success(result) { |
|||
if (result) { |
|||
deferred.resolve(result); |
|||
} else { |
|||
deferred.resolve([]); |
|||
} |
|||
}, function fail() { |
|||
deferred.reject(); |
|||
}); |
|||
return deferred.promise; |
|||
} |
|||
|
|||
scope.entitySearchTextChanged = function() { |
|||
} |
|||
|
|||
scope.updateView = function () { |
|||
if (!scope.disabled) { |
|||
ngModelCtrl.$setViewValue(scope.entity ? scope.entity.id.id : null); |
|||
} |
|||
} |
|||
|
|||
ngModelCtrl.$render = function () { |
|||
if (ngModelCtrl.$viewValue) { |
|||
entityService.getEntity(scope.entityType, ngModelCtrl.$viewValue).then( |
|||
function success(entity) { |
|||
scope.entity = entity; |
|||
}, |
|||
function fail() { |
|||
scope.entity = null; |
|||
} |
|||
); |
|||
} else { |
|||
scope.entity = null; |
|||
} |
|||
} |
|||
|
|||
scope.$watch('entityType', function () { |
|||
load(); |
|||
}); |
|||
|
|||
scope.$watch('entitySubtype', function () { |
|||
if (scope.entity && scope.entity.type != scope.entitySubtype) { |
|||
scope.entity = null; |
|||
scope.updateView(); |
|||
} |
|||
}); |
|||
|
|||
scope.$watch('entity', function () { |
|||
scope.updateView(); |
|||
}); |
|||
|
|||
scope.$watch('disabled', function () { |
|||
scope.updateView(); |
|||
}); |
|||
|
|||
|
|||
function load() { |
|||
switch (scope.entityType) { |
|||
case types.entityType.asset: |
|||
scope.selectEntityText = 'asset.select-asset'; |
|||
scope.entityText = 'asset.asset'; |
|||
scope.noEntitiesMatchingText = 'asset.no-assets-matching'; |
|||
scope.entityRequiredText = 'asset.asset-required' |
|||
break; |
|||
case types.entityType.device: |
|||
scope.selectEntityText = 'device.select-device'; |
|||
scope.entityText = 'device.device'; |
|||
scope.noEntitiesMatchingText = 'device.no-devices-matching'; |
|||
scope.entityRequiredText = 'device.device-required' |
|||
break; |
|||
case types.entityType.rule: |
|||
scope.selectEntityText = 'rule.select-rule'; |
|||
scope.entityText = 'rule.rule'; |
|||
scope.noEntitiesMatchingText = 'rule.no-rules-matching'; |
|||
scope.entityRequiredText = 'rule.rule-required' |
|||
break; |
|||
case types.entityType.plugin: |
|||
scope.selectEntityText = 'plugin.select-plugin'; |
|||
scope.entityText = 'plugin.plugin'; |
|||
scope.noEntitiesMatchingText = 'plugin.no-plugins-matching'; |
|||
scope.entityRequiredText = 'plugin.plugin-required' |
|||
break; |
|||
case types.entityType.tenant: |
|||
scope.selectEntityText = 'tenant.select-tenant'; |
|||
scope.entityText = 'tenant.tenant'; |
|||
scope.noEntitiesMatchingText = 'tenant.no-tenants-matching'; |
|||
scope.entityRequiredText = 'tenant.tenant-required' |
|||
break; |
|||
case types.entityType.customer: |
|||
scope.selectEntityText = 'customer.select-customer'; |
|||
scope.entityText = 'customer.customer'; |
|||
scope.noEntitiesMatchingText = 'customer.no-customers-matching'; |
|||
scope.entityRequiredText = 'customer.customer-required' |
|||
break; |
|||
case types.entityType.user: |
|||
scope.selectEntityText = 'user.select-user'; |
|||
scope.entityText = 'user.user'; |
|||
scope.noEntitiesMatchingText = 'user.no-users-matching'; |
|||
scope.entityRequiredText = 'user.user-required' |
|||
break; |
|||
case types.entityType.dashboard: |
|||
scope.selectEntityText = 'dashboard.select-dashboard'; |
|||
scope.entityText = 'dashboard.dashboard'; |
|||
scope.noEntitiesMatchingText = 'dashboard.no-dashboards-matching'; |
|||
scope.entityRequiredText = 'dashboard.dashboard-required' |
|||
break; |
|||
case types.entityType.alarm: |
|||
scope.selectEntityText = 'alarm.select-alarm'; |
|||
scope.entityText = 'alarm.alarm'; |
|||
scope.noEntitiesMatchingText = 'alarm.no-alarms-matching'; |
|||
scope.entityRequiredText = 'alarm.alarm-required' |
|||
break; |
|||
} |
|||
if (scope.entity && scope.entity.id.entityType != scope.entityType) { |
|||
scope.entity = null; |
|||
scope.updateView(); |
|||
} |
|||
} |
|||
|
|||
$compile(element.contents())(scope); |
|||
} |
|||
|
|||
return { |
|||
restrict: "E", |
|||
require: "^ngModel", |
|||
link: linker, |
|||
scope: { |
|||
theForm: '=?', |
|||
tbRequired: '=?', |
|||
disabled:'=ngDisabled', |
|||
entityType: '=', |
|||
entitySubtype: '=?' |
|||
} |
|||
}; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
.tb-entity-autocomplete { |
|||
.tb-entity-item { |
|||
display: block; |
|||
height: 48px; |
|||
} |
|||
li { |
|||
height: auto !important; |
|||
white-space: normal !important; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2017 The Thingsboard Authors |
|||
|
|||
Licensed 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. |
|||
|
|||
--> |
|||
<md-autocomplete ng-required="tbRequired" |
|||
ng-disabled="disabled" |
|||
md-no-cache="true" |
|||
md-input-name="entity" |
|||
ng-model="entity" |
|||
md-selected-item="entity" |
|||
md-search-text="entitySearchText" |
|||
md-search-text-change="entitySearchTextChanged()" |
|||
md-items="item in fetchEntities(entitySearchText)" |
|||
md-item-text="item.name" |
|||
md-min-length="0" |
|||
md-floating-label="{{ entityText | translate }}" |
|||
md-select-on-match="true" |
|||
md-menu-class="tb-entity-autocomplete"> |
|||
<md-item-template> |
|||
<div class="tb-entity-item"> |
|||
<span md-highlight-text="entitySearchText" md-highlight-flags="^i">{{item.name}}</span> |
|||
</div> |
|||
</md-item-template> |
|||
<md-not-found> |
|||
<div class="tb-not-found"> |
|||
<span translate translate-values='{ entity: entitySearchText }'>{{ noEntitiesMatchingText }}</span> |
|||
</div> |
|||
</md-not-found> |
|||
<div ng-messages="theForm.entity.$error"> |
|||
<div translate ng-message="required">{{ entityRequiredText }}</div> |
|||
</div> |
|||
</md-autocomplete> |
|||
@ -0,0 +1,86 @@ |
|||
/* |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
import './entity-select.scss'; |
|||
|
|||
/* eslint-disable import/no-unresolved, import/default */ |
|||
|
|||
import entitySelectTemplate from './entity-select.tpl.html'; |
|||
|
|||
/* eslint-enable import/no-unresolved, import/default */ |
|||
|
|||
/*@ngInject*/ |
|||
export default function EntitySelect($compile, $templateCache) { |
|||
|
|||
var linker = function (scope, element, attrs, ngModelCtrl) { |
|||
var template = $templateCache.get(entitySelectTemplate); |
|||
element.html(template); |
|||
|
|||
scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false; |
|||
scope.model = null; |
|||
|
|||
scope.updateView = function () { |
|||
if (!scope.disabled) { |
|||
var value = ngModelCtrl.$viewValue; |
|||
if (scope.model && scope.model.entityType && scope.model.entityId) { |
|||
if (!value) { |
|||
value = {}; |
|||
} |
|||
value.entityType = scope.model.entityType; |
|||
value.id = scope.model.entityId; |
|||
ngModelCtrl.$setViewValue(value); |
|||
} else { |
|||
ngModelCtrl.$setViewValue(null); |
|||
} |
|||
} |
|||
} |
|||
|
|||
ngModelCtrl.$render = function () { |
|||
if (ngModelCtrl.$viewValue) { |
|||
var value = ngModelCtrl.$viewValue; |
|||
scope.model = {}; |
|||
scope.model.entityType = value.entityType; |
|||
scope.model.entityId = value.id; |
|||
} else { |
|||
scope.model = null; |
|||
} |
|||
} |
|||
|
|||
scope.$watch('model.entityType', function () { |
|||
scope.updateView(); |
|||
}); |
|||
|
|||
scope.$watch('model.entityId', function () { |
|||
scope.updateView(); |
|||
}); |
|||
|
|||
scope.$watch('disabled', function () { |
|||
scope.updateView(); |
|||
}); |
|||
|
|||
$compile(element.contents())(scope); |
|||
} |
|||
|
|||
return { |
|||
restrict: "E", |
|||
require: "^ngModel", |
|||
link: linker, |
|||
scope: { |
|||
theForm: '=?', |
|||
tbRequired: '=?', |
|||
disabled:'=ngDisabled' |
|||
} |
|||
}; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
|
|||
.tb-entity-select { |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2017 The Thingsboard Authors |
|||
|
|||
Licensed 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. |
|||
|
|||
--> |
|||
<div layout='row' class="tb-entity-select"> |
|||
<tb-entity-type-select style="min-width: 100px;" |
|||
ng-model="model.entityType"> |
|||
</tb-entity-type-select> |
|||
<tb-entity-autocomplete flex |
|||
the-form="theForm" |
|||
ng-disabled="disabled" |
|||
tb-required="tbRequired" |
|||
entity-type="model.entityType" |
|||
ng-model="model.entityId"> |
|||
</tb-entity-autocomplete> |
|||
</div> |
|||
@ -0,0 +1,43 @@ |
|||
/* |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
/*@ngInject*/ |
|||
export default function AddRelationDialogController($scope, $mdDialog, types, entityRelationService, from) { |
|||
|
|||
var vm = this; |
|||
|
|||
vm.types = types; |
|||
|
|||
vm.relation = {}; |
|||
vm.relation.from = from; |
|||
vm.relation.type = types.entityRelationType.contains; |
|||
|
|||
vm.add = add; |
|||
vm.cancel = cancel; |
|||
|
|||
function cancel() { |
|||
$mdDialog.cancel(); |
|||
} |
|||
|
|||
function add() { |
|||
$scope.theForm.$setPristine(); |
|||
entityRelationService.saveRelation(vm.relation).then( |
|||
function success() { |
|||
$mdDialog.hide(); |
|||
} |
|||
); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2017 The Thingsboard Authors |
|||
|
|||
Licensed 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. |
|||
|
|||
--> |
|||
<md-dialog aria-label="{{ 'relation.add' | translate }}" style="min-width: 400px;"> |
|||
<form name="theForm" ng-submit="vm.add()"> |
|||
<md-toolbar> |
|||
<div class="md-toolbar-tools"> |
|||
<h2 translate>relation.add</h2> |
|||
<span flex></span> |
|||
<md-button class="md-icon-button" ng-click="vm.cancel()"> |
|||
<ng-md-icon icon="close" aria-label="{{ 'dialog.close' | translate }}"></ng-md-icon> |
|||
</md-button> |
|||
</div> |
|||
</md-toolbar> |
|||
<md-progress-linear class="md-warn" md-mode="indeterminate" ng-disabled="!loading" ng-show="loading"></md-progress-linear> |
|||
<span style="min-height: 5px;" flex="" ng-show="!loading"></span> |
|||
<md-dialog-content> |
|||
<div class="md-dialog-content"> |
|||
<md-content class="md-padding" layout="column"> |
|||
<fieldset ng-disabled="loading"> |
|||
<md-input-container class="md-block"> |
|||
<label translate>relation.relation-type</label> |
|||
<md-select required ng-model="vm.relation.type" ng-disabled="loading"> |
|||
<md-option ng-repeat="type in vm.types.entityRelationType" ng-value="type"> |
|||
<span>{{('relation.relation-types.' + type) | translate}}</span> |
|||
</md-option> |
|||
</md-select> |
|||
</md-input-container> |
|||
<span class="tb-small">{{'entity.entity' | translate }}</span> |
|||
<tb-entity-select flex |
|||
the-form="theForm" |
|||
tb-required="true" |
|||
ng-model="vm.relation.to"> |
|||
</tb-entity-select> |
|||
</fieldset> |
|||
</md-content> |
|||
</div> |
|||
</md-dialog-content> |
|||
<md-dialog-actions layout="row"> |
|||
<span flex></span> |
|||
<md-button ng-disabled="loading || theForm.$invalid || !theForm.$dirty" type="submit" |
|||
class="md-raised md-primary"> |
|||
{{ 'action.add' | translate }} |
|||
</md-button> |
|||
<md-button ng-disabled="loading" ng-click="vm.cancel()" style="margin-right:20px;">{{ 'action.cancel' | |
|||
translate }} |
|||
</md-button> |
|||
</md-dialog-actions> |
|||
</form> |
|||
</md-dialog> |
|||
@ -0,0 +1,179 @@ |
|||
/* |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
import 'angular-material-data-table/dist/md-data-table.min.css'; |
|||
import './relation-table.scss'; |
|||
|
|||
/* eslint-disable import/no-unresolved, import/default */ |
|||
|
|||
import relationTableTemplate from './relation-table.tpl.html'; |
|||
import addRelationTemplate from './add-relation-dialog.tpl.html'; |
|||
|
|||
/* eslint-enable import/no-unresolved, import/default */ |
|||
|
|||
import AddRelationController from './add-relation-dialog.controller'; |
|||
|
|||
/*@ngInject*/ |
|||
export default function RelationTable() { |
|||
return { |
|||
restrict: "E", |
|||
scope: true, |
|||
bindToController: { |
|||
entityId: '=', |
|||
entityType: '@' |
|||
}, |
|||
controller: RelationTableController, |
|||
controllerAs: 'vm', |
|||
templateUrl: relationTableTemplate |
|||
}; |
|||
} |
|||
|
|||
/*@ngInject*/ |
|||
function RelationTableController($scope, $q, $mdDialog, $document, $translate, $filter, utils, types, entityRelationService) { |
|||
|
|||
let vm = this; |
|||
|
|||
vm.relations = []; |
|||
vm.relationsCount = 0; |
|||
vm.allRelations = []; |
|||
vm.selectedRelations = []; |
|||
|
|||
vm.query = { |
|||
order: 'typeName', |
|||
limit: 5, |
|||
page: 1, |
|||
search: null |
|||
}; |
|||
|
|||
vm.enterFilterMode = enterFilterMode; |
|||
vm.exitFilterMode = exitFilterMode; |
|||
vm.onReorder = onReorder; |
|||
vm.onPaginate = onPaginate; |
|||
vm.addRelation = addRelation; |
|||
vm.editRelation = editRelation; |
|||
vm.deleteRelation = deleteRelation; |
|||
vm.deleteRelations = deleteRelations; |
|||
vm.reloadRelations = reloadRelations; |
|||
vm.updateRelations = updateRelations; |
|||
|
|||
|
|||
$scope.$watch("vm.entityId", function(newVal, prevVal) { |
|||
if (newVal && !angular.equals(newVal, prevVal)) { |
|||
reloadRelations(); |
|||
} |
|||
}); |
|||
|
|||
$scope.$watch("vm.query.search", function(newVal, prevVal) { |
|||
if (!angular.equals(newVal, prevVal) && vm.query.search != null) { |
|||
updateRelations(); |
|||
} |
|||
}); |
|||
|
|||
function enterFilterMode () { |
|||
vm.query.search = ''; |
|||
} |
|||
|
|||
function exitFilterMode () { |
|||
vm.query.search = null; |
|||
updateRelations(); |
|||
} |
|||
|
|||
function onReorder () { |
|||
updateRelations(); |
|||
} |
|||
|
|||
function onPaginate () { |
|||
updateRelations(); |
|||
} |
|||
|
|||
function addRelation($event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
var from = { |
|||
id: vm.entityId, |
|||
entityType: vm.entityType |
|||
}; |
|||
$mdDialog.show({ |
|||
controller: AddRelationController, |
|||
controllerAs: 'vm', |
|||
templateUrl: addRelationTemplate, |
|||
parent: angular.element($document[0].body), |
|||
locals: { from: from }, |
|||
fullscreen: true, |
|||
targetEvent: $event |
|||
}).then(function () { |
|||
reloadRelations(); |
|||
}, function () { |
|||
}); |
|||
} |
|||
|
|||
function editRelation($event, /*relation*/) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
//TODO:
|
|||
} |
|||
|
|||
function deleteRelation($event, /*relation*/) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
//TODO:
|
|||
} |
|||
|
|||
function deleteRelations($event) { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
//TODO:
|
|||
} |
|||
|
|||
function reloadRelations () { |
|||
vm.allRelations.length = 0; |
|||
vm.relations.length = 0; |
|||
vm.relationsPromise = entityRelationService.findInfoByFrom(vm.entityId, vm.entityType); |
|||
vm.relationsPromise.then( |
|||
function success(allRelations) { |
|||
allRelations.forEach(function(relation) { |
|||
relation.typeName = $translate.instant('relation.relation-type.' + relation.type); |
|||
relation.toEntityTypeName = $translate.instant(utils.entityTypeName(relation.to.entityType)); |
|||
}); |
|||
vm.allRelations = allRelations; |
|||
vm.selectedRelations = []; |
|||
vm.updateRelations(); |
|||
vm.relationsPromise = null; |
|||
}, |
|||
function fail() { |
|||
vm.allRelations = []; |
|||
vm.selectedRelations = []; |
|||
vm.updateRelations(); |
|||
vm.relationsPromise = null; |
|||
} |
|||
) |
|||
} |
|||
|
|||
function updateRelations () { |
|||
vm.selectedRelations = []; |
|||
var result = $filter('orderBy')(vm.allRelations, vm.query.order); |
|||
if (vm.query.search != null) { |
|||
result = $filter('filter')(result, {$: vm.query.search}); |
|||
} |
|||
vm.relationsCount = result.length; |
|||
var startIndex = vm.query.limit * (vm.query.page - 1); |
|||
vm.relations = result.slice(startIndex, startIndex + vm.query.limit); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2017 The Thingsboard Authors |
|||
* |
|||
* Licensed 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. |
|||
*/ |
|||
@import '../../../scss/constants'; |
|||
|
|||
$md-light: rgba(255, 255, 255, 100%); |
|||
|
|||
.tb-relation-table { |
|||
md-toolbar.md-table-toolbar.alternate { |
|||
.md-toolbar-tools { |
|||
md-icon { |
|||
color: $md-light; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,119 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2017 The Thingsboard Authors |
|||
|
|||
Licensed 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. |
|||
|
|||
--> |
|||
<md-content flex class="md-padding tb-absolute-fill tb-relation-table tb-data-table" layout="column"> |
|||
<div layout="column" class="md-whiteframe-z1"> |
|||
<md-toolbar class="md-table-toolbar md-default" ng-show="!vm.selectedRelations.length |
|||
&& vm.query.search === null"> |
|||
<div class="md-toolbar-tools"> |
|||
<span translate>relation.entity-relations</span> |
|||
<span flex></span> |
|||
<md-button class="md-icon-button" ng-click="vm.addRelation($event)"> |
|||
<md-icon>add</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.add' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
<md-button class="md-icon-button" ng-click="vm.enterFilterMode()"> |
|||
<md-icon>search</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.search' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
<md-button class="md-icon-button" ng-click="vm.reloadRelations()"> |
|||
<md-icon>refresh</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.refresh' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
</div> |
|||
</md-toolbar> |
|||
<md-toolbar class="md-table-toolbar md-default" ng-show="!vm.selectedRelations.length |
|||
&& vm.query.search != null"> |
|||
<div class="md-toolbar-tools"> |
|||
<md-button class="md-icon-button" aria-label="{{ 'action.search' | translate }}"> |
|||
<md-icon aria-label="{{ 'action.search' | translate }}" class="material-icons">search</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.search' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
<md-input-container flex> |
|||
<label> </label> |
|||
<input ng-model="vm.query.search" placeholder="{{ 'common.enter-search' | translate }}"/> |
|||
</md-input-container> |
|||
<md-button class="md-icon-button" aria-label="{{ 'action.back' | translate }}" ng-click="vm.exitFilterMode()"> |
|||
<md-icon aria-label="{{ 'action.close' | translate }}" class="material-icons">close</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.close' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
</div> |
|||
</md-toolbar> |
|||
<md-toolbar class="md-table-toolbar alternate" ng-show="vm.selectedRelations.length"> |
|||
<div class="md-toolbar-tools"> |
|||
<span translate |
|||
translate-values="{count: selectedRelations.length}" |
|||
translate-interpolation="messageformat">relation.selected-relations</span> |
|||
<span flex></span> |
|||
<md-button class="md-icon-button" ng-click="vm.deleteRelations($event)"> |
|||
<md-icon>delete</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'action.delete' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
</div> |
|||
</md-toolbar> |
|||
<md-table-container> |
|||
<table md-table md-row-select multiple="" ng-model="vm.selectedRelations" md-progress="vm.relationsDeferred.promise"> |
|||
<thead md-head md-order="vm.query.order" md-on-reorder="vm.onReorder"> |
|||
<tr md-row> |
|||
<th md-column md-order-by="typeName"><span translate>relation.type</span></th> |
|||
<th md-column md-order-by="toEntityTypeName"><span translate>relation.to-entity-type</span></th> |
|||
<th md-column md-order-by="toName"><span translate>relation.to-entity-name</span></th> |
|||
<th md-column><span> </span></th> |
|||
</tr> |
|||
</thead> |
|||
<tbody md-body> |
|||
<tr md-row md-select="relation" md-select-id="relation" md-auto-select ng-repeat="relation in vm.relations"> |
|||
<td md-cell>{{ relation.typeName }}</td> |
|||
<td md-cell>{{ relation.toEntityTypeName }}</td> |
|||
<td md-cell>{{ relation.toName }}</td> |
|||
<td md-cell class="tb-action-cell"> |
|||
<md-button class="md-icon-button" aria-label="{{ 'action.edit' | translate }}" |
|||
ng-click="vm.editRelation($event, relation)"> |
|||
<md-icon aria-label="{{ 'action.edit' | translate }}" class="material-icons">edit</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'relation.edit' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
<md-button class="md-icon-button" aria-label="{{ 'action.delete' | translate }}" ng-click="vm.deleteRelation($event, relation)"> |
|||
<md-icon aria-label="{{ 'action.delete' | translate }}" class="material-icons">delete</md-icon> |
|||
<md-tooltip md-direction="top"> |
|||
{{ 'relation.delete' | translate }} |
|||
</md-tooltip> |
|||
</md-button> |
|||
</td> |
|||
</tr> |
|||
</tbody> |
|||
</table> |
|||
</md-table-container> |
|||
<md-table-pagination md-limit="vm.query.limit" md-limit-options="[5, 10, 15]" |
|||
md-page="vm.query.page" md-total="{{vm.relationsCount}}" |
|||
md-on-paginate="onPaginate" md-page-select> |
|||
</md-table-pagination> |
|||
</div> |
|||
</md-content> |
|||
Loading…
Reference in new issue