Skip to content

Commit

Permalink
integrate v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
alberts-tid committed Jun 10, 2014
1 parent 155965c commit fdeb2ee
Show file tree
Hide file tree
Showing 8 changed files with 505 additions and 469 deletions.
596 changes: 301 additions & 295 deletions core/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@
import static java.text.MessageFormat.format;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.telefonica.euro_iaas.sdc.exception.InstallatorException;
import com.telefonica.euro_iaas.sdc.exception.InvalidInstallProductRequestException;
Expand All @@ -47,6 +54,7 @@
import com.telefonica.euro_iaas.sdc.model.Attribute;
import com.telefonica.euro_iaas.sdc.model.ProductInstance;
import com.telefonica.euro_iaas.sdc.model.ProductRelease;
import com.telefonica.euro_iaas.sdc.model.dto.NodeDto;
import com.telefonica.euro_iaas.sdc.model.dto.VM;

public class InstallatorPuppetImpl implements Installator {
Expand All @@ -66,20 +74,38 @@ public void callService(VM vm, String vdc, ProductRelease product, String action
} catch (OpenStackException e) {
throw new SdcRuntimeException(e);
}
HttpPost postInstall = new HttpPost(puppetUrl + action + "/" + vdc + "/" + vm.getHostname() + "/"
+ product.getProduct().getName() + "/" + product.getVersion());
HttpPost postInstall = new HttpPost(puppetUrl + "v2/node/"+ vm.getHostname() + "/"
+ action);

postInstall.addHeader("Content-Type", "application/json");

NodeDto nodeDto = new NodeDto(vdc,product.getProduct().getName(),product.getVersion());
ObjectMapper mapper = new ObjectMapper();
StringEntity input;

try {
input = new StringEntity(mapper.writeValueAsString(nodeDto));
} catch (JsonGenerationException e2) {
throw new SdcRuntimeException(e2);
} catch (JsonMappingException e2) {
throw new SdcRuntimeException(e2);
} catch (UnsupportedEncodingException e2) {
throw new SdcRuntimeException(e2);
} catch (IOException e2) {
throw new SdcRuntimeException(e2);
}

input.setContentType("application/json");
postInstall.setEntity(input);

System.out.println("puppetURL: " + puppetUrl + action + "/" + vdc + "/" + vm.getHostname() + "/"
+ product.getProduct().getName() + "/" + product.getVersion());
// System.out.println("puppetURL: " + puppetUrl + "v2/node/"+ vm.getHostname() + "/"
// + action);

HttpResponse response;

log.info("Calling puppetWrapper install");
log.debug("connecting to puppetURL: "+puppetUrl
+ action + "/" + vdc + "/" + vm.getHostname() + "/" + product.getProduct().getName() + "/"
+ product.getVersion());
log.debug("connecting to puppetURL: "+"puppetURL: " + puppetUrl + "v2/node/"+ vm.getHostname() + "/"
+ action);
try {
response = client.execute(postInstall);
int statusCode = response.getStatusLine().getStatusCode();
Expand All @@ -94,15 +120,14 @@ public void callService(VM vm, String vdc, ProductRelease product, String action
log.debug("statusCode:"+ statusCode);

log.info("Calling puppetWrapper generate");
log.debug(puppetUrl + "generate/"
+ vm.getHostname());
log.debug(puppetUrl + "v2/node/"+vm.getHostname()+"/generate");

// generate files in puppet master
HttpPost postGenerate = new HttpPost(puppetUrl + "generate/" + vm.getHostname());
HttpGet getGenerate = new HttpGet(puppetUrl + "v2/node/"+vm.getHostname()+"/generate");

postGenerate.addHeader("Content-Type", "application/json");
getGenerate.addHeader("Content-Type", "application/json");

response = client.execute(postGenerate);
response = client.execute(getGenerate);
statusCode = response.getStatusLine().getStatusCode();
entity = response.getEntity();
EntityUtils.consume(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void puppetDelete(String vdc, String nodeName, String token) throws Node

HttpDelete delete;
try {
delete = new HttpDelete(openStackRegion.getPuppetWrapperEndPoint(token) + "delete/node/" + nodeName);
delete = new HttpDelete(openStackRegion.getPuppetWrapperEndPoint(token) + "v2/node/" + nodeName);
} catch (OpenStackException e2) {
log.info(e2.getMessage());
throw new NodeExecutionException(e2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HTTP;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.test.annotation.ExpectedException;

import com.telefonica.euro_iaas.sdc.dao.ChefClientConfig;
import com.telefonica.euro_iaas.sdc.exception.InstallatorException;
import com.telefonica.euro_iaas.sdc.exception.NodeExecutionException;
import com.telefonica.euro_iaas.sdc.exception.OpenStackException;
Expand Down Expand Up @@ -123,9 +120,10 @@ public void testCallService_all_OK() throws InstallatorException, NodeExecutionE
}

@Test(expected = InstallatorException.class)
public void testCallService_FAIL() throws InstallatorException, NodeExecutionException{
public void testCallService_FAIL() throws InstallatorException, NodeExecutionException, OpenStackException{

when(statusLine.getStatusCode()).thenReturn(500);
// when(openStackRegion.getPuppetWrapperEndPoint(anyString())).thenReturn("http://testurl.es");

puppetInstallator.callService(host,"test",productRelease, "install", "token");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* </p>
*/

package com.telefonica.euro_iaas.sdc.puppetwrapper.dto;
package com.telefonica.euro_iaas.sdc.model.dto;

public class NodeDto {

Expand Down

0 comments on commit fdeb2ee

Please sign in to comment.