Skip to content

Commit

Permalink
Merge pull request #445 from devicehive/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tmatvienko authored Dec 11, 2017
2 parents 9a1a5ce + 1a1541e commit 2d021a2
Show file tree
Hide file tree
Showing 79 changed files with 453 additions and 155 deletions.
36 changes: 18 additions & 18 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ node('docker') {
stage('Build and publish Docker images in CI repository') {
echo 'Building images ...'
unstash 'jars'
def auth = docker.build('devicehiveci/devicehive-auth-rdbms:${BRANCH_NAME}', '-f dockerfiles/devicehive-auth-rdbms.Dockerfile .')
def plugin = docker.build('devicehiveci/devicehive-plugin-rdbms:${BRANCH_NAME}', '-f dockerfiles/devicehive-plugin-rdbms.Dockerfile .')
def frontend = docker.build('devicehiveci/devicehive-frontend-rdbms:${BRANCH_NAME}', '-f dockerfiles/devicehive-frontend-rdbms.Dockerfile .')
def backend = docker.build('devicehiveci/devicehive-backend-rdbms:${BRANCH_NAME}', '-f dockerfiles/devicehive-backend-rdbms.Dockerfile .')
def auth = docker.build('devicehiveci/devicehive-auth:${BRANCH_NAME}', '-f dockerfiles/devicehive-auth.Dockerfile .')
def plugin = docker.build('devicehiveci/devicehive-plugin:${BRANCH_NAME}', '-f dockerfiles/devicehive-plugin.Dockerfile .')
def frontend = docker.build('devicehiveci/devicehive-frontend:${BRANCH_NAME}', '-f dockerfiles/devicehive-frontend.Dockerfile .')
def backend = docker.build('devicehiveci/devicehive-backend:${BRANCH_NAME}', '-f dockerfiles/devicehive-backend.Dockerfile .')
def hazelcast = docker.build('devicehiveci/devicehive-hazelcast:${BRANCH_NAME}', '-f dockerfiles/devicehive-hazelcast.Dockerfile .')

echo 'Pushing images to CI repository ...'
Expand Down Expand Up @@ -63,9 +63,9 @@ if (publishable_branches.contains(env.BRANCH_NAME)) {
}

echo("Wait for devicehive")
timeout(time:2, unit: 'MINUTES') {
timeout(time:5, unit: 'MINUTES') {
waitUntil{
def fe_status = sh script: 'curl --output /dev/null --silent --head --fail "http://127.0.0.1:8080/api/rest/info"', returnStatus: true
def fe_status = sh script: 'curl --output /dev/null --silent --head --fail "http://127.0.0.1/api/rest/info"', returnStatus: true
return (fe_status == 0)
}
}
Expand All @@ -84,11 +84,11 @@ if (publishable_branches.contains(env.BRANCH_NAME)) {
sh '''
cp config.json config.json.orig
cat config.json.orig | \\
jq ".server.wsUrl = \\"ws://127.0.0.1:8080/api/websocket\\"" | \\
jq ".server.wsUrl = \\"ws://127.0.0.1/api/websocket\\"" | \\
jq ".server.ip = \\"127.0.0.1\\"" | \\
jq ".server.port = \\"8080\\"" | \\
jq ".server.restUrl = \\"http://127.0.0.1:8080/api/rest\\"" | \\
jq ".server.authRestUrl = \\"http://127.0.0.1:8090/api/rest\\"" > config.json
jq ".server.port = \\"80\\"" | \\
jq ".server.restUrl = \\"http://127.0.0.1/api/rest\\"" | \\
jq ".server.authRestUrl = \\"http://127.0.0.1/auth/rest\\"" > config.json
'''

timeout(time:10, unit: 'MINUTES') {
Expand Down Expand Up @@ -117,17 +117,17 @@ if (publishable_branches.contains(env.BRANCH_NAME)) {

docker.withRegistry('https://registry.hub.docker.com', 'devicehiveci_dockerhub'){
sh """
docker tag devicehiveci/devicehive-auth-rdbms:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-auth-rdbms:${IMAGE_TAG}
docker tag devicehiveci/devicehive-frontend-rdbms:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-frontend-rdbms:${IMAGE_TAG}
docker tag devicehiveci/devicehive-backend-rdbms:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-backend-rdbms:${IMAGE_TAG}
docker tag devicehiveci/devicehive-auth:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-auth:${IMAGE_TAG}
docker tag devicehiveci/devicehive-frontend:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-frontend:${IMAGE_TAG}
docker tag devicehiveci/devicehive-backend:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-backend:${IMAGE_TAG}
docker tag devicehiveci/devicehive-hazelcast:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-hazelcast:${IMAGE_TAG}
docker tag devicehiveci/devicehive-plugin-rdbms:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-plugin-rdbms:${IMAGE_TAG}
docker tag devicehiveci/devicehive-plugin:${BRANCH_NAME} registry.hub.docker.com/devicehive/devicehive-plugin:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-auth-rdbms:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-frontend-rdbms:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-backend-rdbms:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-auth:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-frontend:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-backend:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-hazelcast:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-plugin-rdbms:${IMAGE_TAG}
docker push registry.hub.docker.com/devicehive/devicehive-plugin:${IMAGE_TAG}
"""
}
}
Expand Down
2 changes: 1 addition & 1 deletion devicehive-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>devicehive-server</artifactId>
<groupId>com.devicehive</groupId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public interface AuthApiInfoResource {
response = ApiInfoVO.class),
})
Response getApiInfo(@Context UriInfo uriInfo,
@HeaderParam("X-DH-wss-enabled")
@DefaultValue("false")
Boolean wssEnabled);
@HeaderParam("X-Forwarded-Proto")
@DefaultValue("http")
String protocol);

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AuthApiInfoResourceImpl(BaseApiInfoResource baseApiInfoResource) {
}

@Override
public Response getApiInfo(UriInfo uriInfo, Boolean wssEnabled) {
return baseApiInfoResource.getApiInfo(uriInfo, wssEnabled);
public Response getApiInfo(UriInfo uriInfo, String protocol) {
return baseApiInfoResource.getApiInfo(uriInfo, protocol);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private Response getRefreshResponse(JwtUserPayload payload) {

JwtTokenVO responseTokenVO = new JwtTokenVO();
responseTokenVO.setAccessToken(tokenService.generateJwtAccessToken(payload, false));
userService.refreshUserLoginData(user);
logger.debug("JwtToken: access token successfully generated with refresh token");
return ResponseFactory.response(CREATED, responseTokenVO, JsonPolicyDef.Policy.JWT_ACCESS_TOKEN_SUBMITTED);
}
Expand Down
4 changes: 2 additions & 2 deletions devicehive-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>devicehive-server</artifactId>
<groupId>com.devicehive</groupId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -72,7 +72,7 @@
<profile>
<id>proxy-ws-kafka</id>
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* #L%
*/

import com.devicehive.api.HandlersMapper;
import com.devicehive.messages.handler.DeviceCreateHandler;
import com.devicehive.messages.handler.DeviceDeleteHandler;
import com.devicehive.messages.handler.PluginSubscribeRequestHandler;
import com.devicehive.messages.handler.PluginUnsubscribeRequestHandler;
import com.devicehive.messages.handler.command.CommandGetSubscriptionRequestHandler;
Expand All @@ -46,11 +48,10 @@
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class RequestHandlersMapper {
public class RequestHandlersMapper implements HandlersMapper {

private final NotificationSearchHandler notificationSearchHandler;
private final NotificationInsertHandler notificationInsertHandler;
Expand All @@ -69,6 +70,7 @@ public class RequestHandlersMapper {
private final ListDeviceHandler listDeviceHandler;
private final ListSubscribeHandler listSubscribeHandler;
private final DeviceCreateHandler deviceCreateHandler;
private final DeviceDeleteHandler deviceDeleteHandler;
private final PluginSubscribeRequestHandler pluginSubscribeRequestHandler;
private final PluginUnsubscribeRequestHandler pluginUnsubscribeRequestHandler;

Expand All @@ -90,6 +92,7 @@ public RequestHandlersMapper(CommandUpdateHandler commandUpdateHandler,
ListNetworkHandler listNetworkHandler,
ListSubscribeHandler listSubscribeHandler,
DeviceCreateHandler deviceCreateHandler,
DeviceDeleteHandler deviceDeleteHandler,
CommandSubscribeRequestHandler commandSubscribeRequestHandler,
CommandUnsubscribeRequestHandler commandUnsubscribeRequestHandler,
CommandUpdateSubscribeRequestHandler commandUpdateSubscribeRequestHandler,
Expand All @@ -109,11 +112,13 @@ public RequestHandlersMapper(CommandUpdateHandler commandUpdateHandler,
this.listNetworkHandler = listNetworkHandler;
this.listSubscribeHandler = listSubscribeHandler;
this.deviceCreateHandler = deviceCreateHandler;
this.deviceDeleteHandler = deviceDeleteHandler;
this.commandSubscribeRequestHandler = commandSubscribeRequestHandler;
this.commandUnsubscribeRequestHandler = commandUnsubscribeRequestHandler;
this.commandUpdateSubscribeRequestHandler = commandUpdateSubscribeRequestHandler;
this.pluginSubscribeRequestHandler = pluginSubscribeRequestHandler;
this.pluginUnsubscribeRequestHandler = pluginUnsubscribeRequestHandler;

}

@PostConstruct
Expand All @@ -138,9 +143,11 @@ public void init() {
.put(Action.LIST_DEVICE_REQUEST, listDeviceHandler)
.put(Action.LIST_SUBSCRIBE_REQUEST, listSubscribeHandler)
.put(Action.DEVICE_CREATE_REQUEST, deviceCreateHandler)
.put(Action.DEVICE_DELETE_REQUEST, deviceDeleteHandler)
.build();
}

@Override
public Map<Action, RequestHandler> requestHandlerMap() {
return requestHandlerMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.devicehive.model.eventbus.events.Event;
import com.devicehive.shim.api.Response;
import com.devicehive.shim.api.server.MessageDispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

Expand Down Expand Up @@ -85,4 +83,8 @@ public void publish(Event event) {
dispatcher.send(subscriber.getReplyTo(), response);
});
}

public void unsubscribeDevice(String deviceId) {
registry.unregisterDevice(deviceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@ public Set<Pair<Long, Filter>> getSubscriptions(Long networkId) {
});
return subs;
}

public void unregisterDevice(String deviceId) {
filterSubscriptionsMap.keySet().stream()
.filter(key ->
key.getDeviceIds().contains(deviceId))
.forEach(key -> {
Collection<Long> subscriptionsIds = filterSubscriptionsMap.get(key);
subscriptionsIds.forEach(this::unregister);
key.deleteDeviceId(deviceId);
if (!(key.getDeviceIds().isEmpty() && key.getNetworkIds().isEmpty())) {
subscriptionsIds.forEach(id -> register(key, id));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ Collection<Subscription> getSubscriptions(@NotNull Subscriber subscriber) {
Collection<Subscription> getAllSubscriptions() {
return subscriptions.keySet();
}

synchronized void unregisterDevice(String deviceId) {
subscriptions.keySet().stream()
.filter(key -> key.getEntityId().equals(deviceId))
.forEach(this::unregister);
subscriberSubscriptions.values().stream()
.filter(value -> value.getEntityId().equals(deviceId))
.forEach(this::unregister);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.devicehive.messages.handler;

/*
* #%L
* DeviceHive Common Module
* %%
* Copyright (C) 2016 - 2017 DataArt
* %%
* 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.
* #L%
*/

import com.devicehive.eventbus.EventBus;
import com.devicehive.eventbus.FilterRegistry;
import com.devicehive.model.rpc.DeviceDeleteRequest;
import com.devicehive.model.rpc.DeviceDeleteResponse;
import com.devicehive.shim.api.Request;
import com.devicehive.shim.api.Response;
import com.devicehive.shim.api.server.RequestHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DeviceDeleteHandler implements RequestHandler {

private EventBus eventBus;
private FilterRegistry filterRegistry;

@Autowired
public void setEventBus(EventBus eventBus) {
this.eventBus = eventBus;
}

@Autowired
public void setFilterRegistry(FilterRegistry filterRegistry) {
this.filterRegistry = filterRegistry;
}

@Override
public Response handle(Request request) {
final DeviceDeleteRequest req = (DeviceDeleteRequest) request.getBody();
final String deviceId = req.getDeviceId();

eventBus.unsubscribeDevice(deviceId);
filterRegistry.unregisterDevice(deviceId);

return Response.newBuilder()
.withBody(new DeviceDeleteResponse())
.withCorrelationId(request.getCorrelationId())
.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# #L%
###
spring.profiles.active=rpc-server
#spring.profiles.active=ws-kafka-proxy-backend

hazelcast.group.name=dev
hazelcast.group.password=dev-pass
Expand Down
2 changes: 1 addition & 1 deletion devicehive-common-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>devicehive-server</artifactId>
<groupId>com.devicehive</groupId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

public interface BaseApiInfoResource {

Response getApiInfo(@Context UriInfo uriInfo, Boolean wssEnabled);
Response getApiInfo(@Context UriInfo uriInfo, String protocol);

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public BaseApiInfoResourceImpl(TimestampService timestampService) {
}

@Override
public Response getApiInfo(UriInfo uriInfo, Boolean wssEnabled) {
public Response getApiInfo(UriInfo uriInfo, String protocol) {
logger.debug("ApiInfoVO requested");
ApiInfoVO apiInfo = new ApiInfoVO();
String version = Constants.class.getPackage().getImplementationVersion();
Expand All @@ -72,7 +72,7 @@ public Response getApiInfo(UriInfo uriInfo, Boolean wssEnabled) {

// Generate websocket url based on current request url
int port = uriInfo.getBaseUri().getPort();
String wsScheme = wssEnabled ? "wss" : "ws";
String wsScheme = "https".equals(protocol) ? "wss" : "ws";
if (port == -1) {
apiInfo.setWebSocketServerUrl(wsScheme + "://" + uriInfo.getBaseUri().getHost() + contextPath + "/websocket");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ protected Optional<UserVO> checkPassword(UserVO user, String password) {
if (user.getLoginAttempts()
>= configurationService.getInt(Constants.MAX_LOGIN_ATTEMPTS, Constants.MAX_LOGIN_ATTEMPTS_DEFAULT)) {
user.setStatus(UserStatus.LOCKED_OUT);
logger.info("User with login {} has been locked out after {} login attempts.", user.getLogin(), user.getLoginAttempts());
user.setLoginAttempts(0);
}
userDao.merge(user);
Expand Down
2 changes: 1 addition & 1 deletion devicehive-common-dao/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.devicehive</groupId>
<artifactId>devicehive-server</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>
<artifactId>devicehive-common-dao</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion devicehive-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.devicehive</groupId>
<artifactId>devicehive-server</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>
<artifactId>devicehive-common</artifactId>
<packaging>jar</packaging>
Expand Down
Loading

0 comments on commit 2d021a2

Please sign in to comment.