Skip to content

Commit

Permalink
converter, exceptionMapper, ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Suman BN committed Nov 4, 2016
1 parent 8a8a5f5 commit bc0bc9d
Show file tree
Hide file tree
Showing 15 changed files with 1,230 additions and 3 deletions.
36 changes: 36 additions & 0 deletions fabric-manager/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#Copyright 2016 ANI Technologies Pvt. Ltd.
#
#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:14.04
MAINTAINER [email protected]

RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends software-properties-common \
&& add-apt-repository ppa:webupd8team/java \
&& gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
&& apt-get update \
&& echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections \
&& echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections \
&& apt-get install -y --no-install-recommends oracle-java8-installer \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

EXPOSE 17000

VOLUME /var/log/fabric-manager

COPY target/fabric-manager*.jar fabric-manager.jar
COPY target/classes/docker-compose-config.yml docker-compose-config.yml

CMD sh -c "sleep 20 ; java -jar -Xms${JAVA_PROCESS_MIN_HEAP} -Xmx${JAVA_PROCESS_MAX_HEAP} -XX:+${GC_ALGO} -Dfile.encoding=utf-8 fabric-manager.jar server ${CONFIG_ENV}-config.yml"
93 changes: 93 additions & 0 deletions fabric-manager/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#Copyright 2016 ANI Technologies Pvt. Ltd.
#
#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.

# Zookeeper compose
zookeeper:
image: garland/zookeeper
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"

# MySQL compose
mysql:
image: mysql/mysql-server:latest
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=fabric_manager
ports:
- "3306:3306"

# Artifactory compose
artifactory:
image: mattgruter/artifactory
ports:
- "8080:8080"

# OpenTSDB compose
opentsdb:
image: petergrace/opentsdb-docker:latest
ports:
- "4242:4242"
- "60030:60030"

# Fabric-Manager compose
fabricmanager:
build: .
ports:
- "18000:18000"
volumes:
- /var/log/fabricmanager
# link to zk, artifact, es
links:
- zookeeper
- mysql
- artifactory
- opentsdb
# enviroment valiables
environment:
- FABRIC_MANAGER_CONNECTION_STRING=_fabric-manager._tcp.marathon.mesos.
- ARTIFACTORY_URL=http://artifactory:8080/artifactory
- MARATHON_ENDPOINT=http://localhost:8080/
- MIN_CPU=0.5
- MIN_MEMORY=512
- ALPHA=0.5
- EXECUTOR_DOCKER_IMAGE=localhost:9002/fabric-executor:0.0.1
- METRICS_ENABLED=false
- OPENTSDB_URL=opentsdb:4242
- OPENTSDB_APP_NAME=fabric-manager
- OPENTSDB_NAMESPACE=fabric
- OPENTSDB_PLATFORM=fabric
- OPENTSDB_PERIOD_IN_SEC=30
- ZK_CONNECTION_STRING=zookeeper:2181
- SERVICE_NAME=fabric-manager
- SERVICE_NAMESPACE=fabric
- SERVICE_ENV=dcos
- HOST=192.168.99.100
- PORT_18000=18000
- LOG_LEVEL=INFO
- HIBERNATE_LOG_LEVEL=ERROR
- DB_USER=root
- DB_PASSWORD=password
- DB_URL=jdbc:mysql://mysql:3306/fabric_manager?autoReconnect=true
- DB_MAX_WAIT_FOR_CONNECTION=1s
- DB_MIN_SIZE=8
- DB_MAX_SIZE=32
- DB_CHECK_CONNECTION_WHILE_IDLE=false
- DB_AUTO_EXPORT_DDL_TO_DATABASE=update
- DB_SHOW_SQL=false
- GC_ALGO=UseG1GC
- JAVA_PROCESS_MIN_HEAP=1g
- JAVA_PROCESS_MAX_HEAP=1g
- CONFIG_ENV=docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.olacabs.fabric.manager.dao.impl.ComputationDAO;
import com.olacabs.fabric.manager.dao.impl.GlobalPropertyDAO;
import com.olacabs.fabric.manager.domain.*;
import com.olacabs.fabric.manager.exception.mapper.HttpExceptionMapper;
import com.olacabs.fabric.manager.exception.mapper.RuntimeExceptionMapper;
import com.olacabs.fabric.manager.filter.UserFilter;
import com.olacabs.fabric.manager.managed.OpenTsdbMetricReporter;
Expand Down Expand Up @@ -137,7 +138,7 @@ public void run(final ManagerConfig config, final Environment environment) throw
environment.jersey().register(globalPropertyResource);

environment.jersey().register(RuntimeExceptionMapper.class);
// environment.jersey().register(HttpExceptionMapper.class);
environment.jersey().register(HttpExceptionMapper.class);

environment.jersey().register(UserFilter.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2016 ANI Technologies Pvt. Ltd.
*
* 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 com.olacabs.fabric.manager.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.olacabs.fabric.manager.bean.ExecutorConfig;
import com.olacabs.fabric.manager.exception.FabricManagerException;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.io.IOException;

/**
* Executor config converter .
*/
@Converter
@Slf4j
public class ExecutorConfigConverter implements AttributeConverter<ExecutorConfig, String> {

private final ObjectMapper mapper;

public ExecutorConfigConverter() {
this(new ObjectMapper());
}

public ExecutorConfigConverter(final ObjectMapper mapper) {
this.mapper = mapper;
}

@Override
public String convertToDatabaseColumn(final ExecutorConfig object) {
try {
return mapper.writeValueAsString(object);
} catch (final JsonProcessingException e) {
log.error("Unable to parse component source - {}", e.getMessage(), e);
throw new FabricManagerException(e);
}
}

@Override
public ExecutorConfig convertToEntityAttribute(final String source) {
try {
return mapper.readValue(source, ExecutorConfig.class);
} catch (final IOException e) {
log.error("Unable to parse ExecutorConfig source - {}", e.getMessage(), e);
throw new FabricManagerException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2016 ANI Technologies Pvt. Ltd.
*
* 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 com.olacabs.fabric.manager.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.olacabs.fabric.manager.bean.RuntimeOptions;
import com.olacabs.fabric.manager.exception.FabricManagerException;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.io.IOException;

/**
* Todo .
*/
@Converter
@Slf4j
public class RuntimeOptionsConverter implements AttributeConverter<RuntimeOptions, String> {

private final ObjectMapper mapper;

public RuntimeOptionsConverter() {
this(new ObjectMapper());
}

public RuntimeOptionsConverter(final ObjectMapper mapper) {
this.mapper = mapper;
}

@Override
public String convertToDatabaseColumn(final RuntimeOptions object) {
try {
return mapper.writeValueAsString(object);
} catch (final JsonProcessingException e) {
log.error("Unable to parse component source - {}", e.getMessage(), e);
throw new FabricManagerException(e);
}
}

@Override
public RuntimeOptions convertToEntityAttribute(final String runtimeOptions) {
try {
return mapper.readValue(runtimeOptions, RuntimeOptions.class);
} catch (final IOException e) {
log.error("Unable to parse RuntimeOptions source - {}", e.getMessage(), e);
throw new FabricManagerException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.olacabs.fabric.manager.bean.ExecutorConfig;
import com.olacabs.fabric.manager.bean.RuntimeOptions;

import com.olacabs.fabric.manager.converter.ExecutorConfigConverter;
import com.olacabs.fabric.manager.converter.RuntimeOptionsConverter;
import lombok.*;

/**
Expand All @@ -45,10 +47,10 @@ public class ApplicationDomain extends TenantBaseDomain {
@JoinColumn(name = "computationId")
private ComputationDomain computation;

// @Convert(converter = ExecutorConfigConverter.class)
@Convert(converter = ExecutorConfigConverter.class)
private ExecutorConfig executorConfig;

// @Convert(converter = RuntimeOptionsConverter.class)
@Convert(converter = RuntimeOptionsConverter.class)
private RuntimeOptions runtimeOptions;

private Boolean active = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2016 ANI Technologies Pvt. Ltd.
*
* 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 com.olacabs.fabric.manager.exception.mapper;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpResponseException;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

/**
* Todo .
*/
@Slf4j
public class HttpExceptionMapper implements ExceptionMapper<HttpResponseException> {

@Override
public Response toResponse(final HttpResponseException e) {

final Response defaultResponse =
Response.serverError().entity(ImmutableMap.of("errors", ImmutableList.of(e.getMessage()))).build();

log.error("Error - {}", e.getMessage());

if (e instanceof groovyx.net.http.HttpResponseException) {
return Response.status(e.getStatusCode())
.entity(ImmutableMap.of("errors", ImmutableList.of(e.getMessage()))).build();
}
log.error("Stack trace - ", e);
return defaultResponse;
}
}
Loading

0 comments on commit bc0bc9d

Please sign in to comment.