Skip to content

Commit

Permalink
creatinog of puppet node
Browse files Browse the repository at this point in the history
  • Loading branch information
Henar Munoz committed Aug 28, 2014
1 parent 1add85a commit 3cdd895
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U <br>
* This file is part of FI-WARE project.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License.
* </p>
* <p>
* You may obtain a copy of the License at:<br>
* <br>
* http://www.apache.org/licenses/LICENSE-2.0
* </p>
* <p>
* 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.
* </p>
* <p>
* See the License for the specific language governing permissions and limitations under the License.
* </p>
* <p>
* For those usages not covered by the Apache version 2.0 License please contact with opensource@tid.es
* </p>
*/

package com.telefonica.euro_iaas.sdc.dao;



import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.config.ClientConfig;

public interface PuppetClientConfig extends ClientConfig {

Client getClient ();

}
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ public void isRecipeExecuted(VM vm, String recipe, String token) throws NodeExec

Thread.sleep(time);

PuppetNode node = loadNode (vm.getHostname(), token);
if (node.getCatalogTimestamp ()!=null) {
PuppetNode node = loadNode (vm.getHostname(), token);
log.debug ("get time catalog " + node.getCatalogTimestamp ());
if (node.getCatalogTimestamp ()!=null && !node.getCatalogTimestamp ().equals("null")) {
isExecuted = true;
}
time = time +incremental_time;
Expand Down Expand Up @@ -287,7 +288,6 @@ private String getNodes (String token) throws SdcRuntimeException{
HttpGet getGenerate = new HttpGet(url);
HttpResponse resp= client.execute(getGenerate);
String response = EntityUtils.toString(resp.getEntity());
log.info(response);
return response;
} catch (Exception e) {
log.warn(e.getMessage());
Expand Down Expand Up @@ -317,6 +317,7 @@ public void isNodeRegistered (String hostname, String token) throws CanNotCallCh

}
}
log.debug ("Node " + hostname + " is registered in ChefServer");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public String getPuppetDBEndPoint( String token) throws OpenStackException {
throw new OpenStackException (msn);

}
return "http:" +url+":8080";
return "http://" +url+":8080";
}

public String getChefServerEndPoint( String token) throws OpenStackException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void testIsRecipedExecuted() throws OpenStackException, CanNotCallChefExc

}

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

when(statusLine.getStatusCode()).thenReturn(200).thenReturn(500);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U <br>
* This file is part of FI-WARE project.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License.
* </p>
* <p>
* You may obtain a copy of the License at:<br>
* <br>
* http://www.apache.org/licenses/LICENSE-2.0
* </p>
* <p>
* 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.
* </p>
* <p>
* See the License for the specific language governing permissions and limitations under the License.
* </p>
* <p>
* For those usages not covered by the Apache version 2.0 License please contact with opensource@tid.es
* </p>
*/

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

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
* Models a chef node.
*
* @author Sergio Arroyo
*/
public class PuppetNode {

private final static String RECIPE_ITEM_TEMPLATE = "recipe[{0}]";

private String name;
private String deactivated;
private String catalog_timestamp;
private String facts_timestamp;
private String report_timestamp;

public String getName (){
return name;
}

public String getCatalogTimestamp (){
return catalog_timestamp;
}


@SuppressWarnings("unchecked")
public void fromJson(JSONObject jsonNode) {
name = jsonNode.getString("name");
deactivated = jsonNode.getString("deactivated");
catalog_timestamp = jsonNode.getString("catalog_timestamp");
catalog_timestamp = jsonNode.getString("catalog_timestamp");
report_timestamp = jsonNode.getString("report_timestamp");

}

@SuppressWarnings("unchecked")
public String getNodeName(String stringNodes, String hostname) {

JSONArray array = JSONArray.fromObject(stringNodes);
for(Object js : array){
JSONObject json = (JSONObject)js;
PuppetNode node = new PuppetNode();
node.fromJson(json);
if (node.getName().startsWith(hostname+".")) {
return node.getName();
}
}
return null;
}

@SuppressWarnings("unchecked")
public PuppetNode getNode(String stringNodes, String hostname) {

JSONArray array = JSONArray.fromObject(stringNodes);
for(Object js : array){
JSONObject json = (JSONObject)js;
PuppetNode node = new PuppetNode();
node.fromJson(json);
if (node.getName().startsWith(hostname+".")) {
return node;
}
}
return null;
}

}

0 comments on commit 3cdd895

Please sign in to comment.