DevOps Metadata service holds all the component builds' metadata for implementing such as contintous automatic deployment system and envs info, keys info, env monitoring info, all the info related to Dev and Ops.
When I was implementing a platform service, always required to build rest services, but can not get on-the-shelf examples that can be used for product service, most of the examples do not give the enough implementations that meeting the production level security requirements etc, most only provides simple get started usage. At the same time, lots of people ask the some question in Stackflow and other sites, "is there such on-the-shelf Rest Service examples that support OAuth, built base on common frameworks spring,resteasy,restlet etc, auth by 2-legged OAuth?"
Now, the answer is Yes.
The example is here, this will make people do not have to spend too much time on finding such example, work, and provide them a good start point for building Rest Service with production security requirements implemented using 2-legged oauth.
- Make an able-to-use-for-production base rest project for developing Rest Service basing on Spring and Resteasy; (Done)
- Make Rest Service support OAuth 2 legged base on oauth 1.0; (Done)
- Make Rest Service support Https; (To Do)
- Make curl example to call Rest APIs; (Done)
- Make unit test example that do not start web server then can test Rest API, uses MockDispatcherFactory; (Done)
- Practice Restful api design, design api for each cases(CRUD + actions) (Done)
- Make Rest Cient SDK and get a method that design Rest Client SDK. (Done) learnt: UI models with Rest Service, UI models with End App that calling SDK, in Client SDK, it should have self domain models, this domain models will be used by Client SDK and Client SDK's calling app.
- Make Rest Docs and make a framework for making rest docs for future use. (To Do)
- Make have easy to use Rest API exception handling that using Resteasy ExceptionHandler to return error message json when there is exception while normally return normal response json. need to use @Component to make ExceptionHandler load by spring-resteasy. (Done)
- With easy to use Validation Framework (To Do)
- Make unit test example that build base on spring test framework (Done)
- Make bootstrap Admin UI example. (To Do)
- Make Cobertura Test Coverage usage example (To Do)
- Make unit tests examples for CRUD APIs, in setup and teardown create and delete, in createTest Case verify if is created. (Done)
- Add version to url, just like v1beta1 in https://www.googleapis.com/container/v1beta1/projects/PROJECT_ID/clusters
- Deployment
- Maven 2.0.9 or higher
Added client module. The module shows an example to test the existing war generated by the service module using the same web container: jetty6 in an embedded mode. The container is injected in the junit 4 test. The client makes use of the resteasy client framework.
- Configuration and override Configurations
defautlt configuration: classpath*:/application.properties override Configurations: file:/var/flysnow/buildmeta/application.properties
can configure db properties in application.properties
- Create database and tables
mysql -usrc/main/resources/dbdeploy/buildmeta_2014-09-09.sql
- Run
cd $HOME
mvn jetty:run
- Run Unit Test
- Run all unit tests
mvn test -Dtest=BuildRestServiceUnitTest
- Run a test case specified
mvn test -Dtest=BuildRestServiceSmokeTest#testCreateBuildInfoAPI
mvn test -Dtest=BuildRestServiceSmokeTest#testGetBuildsByParams
- Run SmokeTest
- Run BuildMetadata Service
mvn jetty:run
- Run Smoke Test
mvn test -Dtest=BuildRestServiceSmokeTest
mvn test -Dtest=BuildMetadataServiceSmokeTest
- Call Rest APIs by curl
- Set logger logging level
curl -v -X GET -H "Content-Type: application/json" http://localhost:8080/ws/logging/org.flysnow/DEBUG
- Debug Tools
- change logging level
curl -v -X GET -H "Content-Type: application/json" http://localhost:8080/ws/logging/org.flysnow/DEBUG
- Disable API oauth
in file src/main/webapp/WEB-INF/applicationContext.xml comment /ws/builds
import OAuth2LeggedClient import requests
class BuildMetaWSOauthClient(object): ''' classdocs '''
def __init__(self):
'''
Constructor
'''
self.apiUrl="http://localhost:8080/ws/builds/data"
self.oauthKey="devops"
self.oauthSecret="devops2014"
pass
def getBuilds(self):
import json
oauth_publishapi = OAuth2LeggedClient.generateOAuthRequestUrl(base_url = self.apiUrl,
comsumer_key = self.oauthKey,
comsumer_secret = self.oauthSecret,
http_method = "GET")
try:
headers = {'content-type': 'application/json'}
r = requests.get(oauth_publishapi, headers={"content-type":"application/json"}, timeout=30)
print r.headers['content-type']
#r = requests.post(oauth_publishapi,headers=request_header, timeout=30)
logger.info(str(r.status_code))
logger.info(r.text)
except Exception, e:
logger.error(str(e))
pass
client = BuildMetaWSOauthClient() client.getBuilds()