mirror of https://github.com/apache/jclouds.git
Issue 191: added ohai for java
This commit is contained in:
parent
35a766c0fa
commit
06ecdb8d7a
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
$HeadURL$ $Revision$ $Date$ Copyright (C) 2009 Cloud Conscious, LLC
|
||||
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious, LLC
|
||||
<info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
|
|
|
@ -78,7 +78,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@Headers(keys = "X-Chef-Version", values = ChefAsyncClient.VERSION)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface ChefAsyncClient {
|
||||
public static final String VERSION = "0.9.6";
|
||||
public static final String VERSION = "0.9.8";
|
||||
|
||||
/**
|
||||
* @see ChefClient#getUploadSandboxForChecksums
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -16,29 +16,6 @@
|
|||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.jclouds.chef.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
|
@ -64,8 +41,6 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
|
@ -130,7 +105,7 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
install(new ChefParserModule());
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -26,6 +26,8 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.chef.domain.DataBagItem;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -79,5 +81,6 @@ public class ChefParserModule extends AbstractModule {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* Gathers Ohai data from the JVM.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class JMX implements Supplier<Map<String, JsonBall>> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final Provider<RuntimeMXBean> runtimeSupplier;
|
||||
|
||||
@Inject
|
||||
public JMX(Provider<RuntimeMXBean> runtimeSupplier) {
|
||||
this.runtimeSupplier = checkNotNull(runtimeSupplier, "runtimeSupplier");
|
||||
}
|
||||
|
||||
public Map<String, JsonBall> get() {
|
||||
RuntimeMXBean runtime = runtimeSupplier.get();
|
||||
Map<String, JsonBall> automatic = Maps.newLinkedHashMap();
|
||||
long uptimeInSeconds = runtime.getUptime() / 1000;
|
||||
automatic.put("uptime_seconds", new JsonBall(uptimeInSeconds));
|
||||
return automatic;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.ChefClient;
|
||||
import org.jclouds.chef.domain.Node;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* Updates node with new automatic attributes.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class UpdateNode {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final ChefClient chef;
|
||||
private final Supplier<Map<String, JsonBall>> automaticSupplier;
|
||||
|
||||
@Inject
|
||||
public UpdateNode(ChefClient chef, @Named("automatic") Supplier<Map<String, JsonBall>> automaticSupplier) {
|
||||
this.chef = checkNotNull(chef, "chef");
|
||||
this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier");
|
||||
}
|
||||
|
||||
public void updateNode(String nodeName) {
|
||||
logger.info("updating node %s", nodeName);
|
||||
Node node = chef.getNode(nodeName);
|
||||
node.getAutomatic().putAll(automaticSupplier.get());
|
||||
chef.updateNode(node);
|
||||
logger.debug("done updating node %s", nodeName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.internal.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* Gathers Ohai data from the JVM. Note that this is intended to be Google App
|
||||
* Engine compatible, so please do not access the network, JMX, or other classes
|
||||
* not on the whitelist.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class WhiteListCompliantJVM implements Supplier<Map<String, JsonBall>> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Function<byte[], String> byteArrayToMacAddress;
|
||||
private final NetworkInterface defaultNetworkInterface;
|
||||
private final Json json;
|
||||
private final Provider<Long> nanoTimeProvider;
|
||||
private final Provider<Properties> systemPropertiesProvider;
|
||||
|
||||
@Inject
|
||||
public WhiteListCompliantJVM(Json json, Function<byte[], String> byteArrayToMacAddress,
|
||||
@Named("nanoTime") Provider<Long> nanoTimeProvider,
|
||||
@Named("systemProperties") Provider<Properties> systemPropertiesProvider,
|
||||
NetworkInterface defaultNetworkInterface) {
|
||||
this.json = checkNotNull(json, "json");
|
||||
this.byteArrayToMacAddress = checkNotNull(byteArrayToMacAddress, "byteArrayToMacAddress");
|
||||
this.nanoTimeProvider = checkNotNull(nanoTimeProvider, "nanoTimeProvider");
|
||||
this.systemPropertiesProvider = checkNotNull(systemPropertiesProvider, "systemPropertiesProvider");
|
||||
this.defaultNetworkInterface = checkNotNull(defaultNetworkInterface, "defaultNetworkInterface");
|
||||
}
|
||||
|
||||
public Map<String, JsonBall> get() {
|
||||
Map<String, JsonBall> returnVal = Maps.newLinkedHashMap();
|
||||
Properties systemProperties = systemPropertiesProvider.get();
|
||||
String now = nanoTimeProvider.get() + "";
|
||||
StringBuilder nowBuilder = new StringBuilder(now).insert(now.length() - 6, '.');
|
||||
while (nowBuilder.lastIndexOf("0") != -1 && nowBuilder.lastIndexOf("0") == nowBuilder.length() - 1)
|
||||
nowBuilder.deleteCharAt(nowBuilder.length() - 1);
|
||||
now = nowBuilder.toString();
|
||||
|
||||
returnVal.put("ohai_time", new JsonBall(now));
|
||||
returnVal.put("java", new JsonBall(json.toJson(systemProperties)));
|
||||
|
||||
try {
|
||||
String mac = byteArrayToMacAddress.apply(defaultNetworkInterface.getHardwareAddress());
|
||||
returnVal.put("macaddress", new JsonBall(mac));
|
||||
} catch (SocketException e) {
|
||||
logger.warn(e, "could not read address from %s", defaultNetworkInterface.getDisplayName());
|
||||
}
|
||||
|
||||
String platform = systemProperties.getProperty("os.name");
|
||||
platform = platform.replaceAll("[ -]", "").toLowerCase();
|
||||
|
||||
returnVal.put("platform", new JsonBall(platform));
|
||||
returnVal.put("platform_version", new JsonBall(systemProperties.getProperty("os.version")));
|
||||
|
||||
returnVal.put("ohai_time", new JsonBall(now));
|
||||
returnVal.put("current_user", new JsonBall(systemProperties.getProperty("user.name")));
|
||||
return returnVal;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai.config;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.ohai.WhiteListCompliantJVM;
|
||||
import org.jclouds.ohai.functions.ByteArrayToMacAddress;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Wires the components needed to parse ohai data from a JVM
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseOhaiModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<byte[], String>>() {
|
||||
}).to(new TypeLiteral<ByteArrayToMacAddress>() {
|
||||
});
|
||||
}
|
||||
|
||||
@Named("nanoTime")
|
||||
@Provides
|
||||
protected Long nanoTime() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
@Named("systemProperties")
|
||||
@Provides
|
||||
protected Properties systemProperties() {
|
||||
return System.getProperties();
|
||||
}
|
||||
|
||||
@Named("automatic")
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<Map<String, JsonBall>> automaticSupplier(
|
||||
@Named("automatic") Iterable<Supplier<Map<String, JsonBall>>> suppliers) {
|
||||
return Utils.composeMapSupplier(suppliers);
|
||||
}
|
||||
|
||||
@Named("automatic")
|
||||
@Singleton
|
||||
@Provides
|
||||
Iterable<Supplier<Map<String, JsonBall>>> suppliers(Injector injector) {
|
||||
return ImmutableList.<Supplier<Map<String, JsonBall>>> of(injector.getInstance(WhiteListCompliantJVM.class));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected NetworkInterface provideDefaultNetworkInterface() throws SocketException {
|
||||
return NetworkInterface.getNetworkInterfaces().nextElement();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai.config;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.ohai.JMX;
|
||||
import org.jclouds.ohai.WhiteListCompliantJVM;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Wires the components needed to parse ohai data from a JVM
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class OhaiModule extends BaseOhaiModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected RuntimeMXBean provideRuntimeMXBean() {
|
||||
return ManagementFactory.getRuntimeMXBean();
|
||||
}
|
||||
|
||||
@Override
|
||||
Iterable<Supplier<Map<String, JsonBall>>> suppliers(Injector injector) {
|
||||
return ImmutableList.<Supplier<Map<String, JsonBall>>> of(injector.getInstance(WhiteListCompliantJVM.class),
|
||||
injector.getInstance(JMX.class));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai.config;
|
||||
|
||||
/**
|
||||
* Wires the components needed to parse ohai data without violating the GAE JVM
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class WhiteListCompliantOhaiModule extends BaseOhaiModule {
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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 org.jclouds.ohai.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Lists.partition;
|
||||
import static com.google.common.primitives.Bytes.asList;
|
||||
import static com.google.common.primitives.Bytes.toArray;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
*
|
||||
* Creates a string in the form: {@code 00:26:bb:09:e6:c4 }
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ByteArrayToMacAddress implements Function<byte[], String> {
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
ByteArrayToMacAddress(EncryptionService encryptionService, NetworkInterface networkInterface) {
|
||||
this.encryptionService = checkNotNull(encryptionService, "encryptionService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(byte[] from) {
|
||||
return Joiner.on(':').join(transform(partition(asList(from), 1), new Function<List<Byte>, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(List<Byte> from) {
|
||||
return encryptionService.hex(toArray(from));
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -76,7 +76,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -95,7 +95,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")), Bytes.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0"))));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}",
|
||||
|
@ -113,7 +113,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("getCookbook", String.class, String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -128,7 +128,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("deleteCookbook", String.class, String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -146,7 +146,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
new CookbookVersion("cookbook", "1.0.1"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}",
|
||||
|
@ -164,7 +164,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
|
@ -179,7 +179,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||
|
@ -194,7 +194,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -210,7 +210,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
|
@ -226,7 +226,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
|
@ -241,7 +241,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
|
@ -256,7 +256,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("nodeExists", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "node");
|
||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/nodes/node HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||
|
@ -271,7 +271,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("deleteNode", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "node");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/nodes/node HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -288,7 +288,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
ImmutableSet.of("recipe[java]")));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/nodes HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
||||
|
@ -308,7 +308,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
ImmutableSet.of("recipe[java]")));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/nodes/testnode HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
||||
|
@ -327,7 +327,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/nodes HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
|
@ -342,7 +342,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("roleExists", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "role");
|
||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/roles/role HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||
|
@ -357,7 +357,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("deleteRole", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "role");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/roles/role HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
|
@ -374,7 +374,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
ImmutableSet.of("recipe[java]")));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/roles HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}",
|
||||
|
@ -394,7 +394,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
ImmutableSet.of("recipe[java]")));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/roles/testrole HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}",
|
||||
|
@ -413,7 +413,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/roles HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
@ -30,9 +30,10 @@ import java.net.URI;
|
|||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -45,7 +46,7 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "unit", testName = "chef.BindHexEncodedMD5sToJsonPayloadTest")
|
||||
public class BindHexEncodedMD5sToJsonPayloadTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
BindChecksumsToJsonPayload binder = injector.getInstance(BindChecksumsToJsonPayload.class);
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
|
@ -57,10 +58,9 @@ public class BindHexEncodedMD5sToJsonPayloadTest {
|
|||
@Test(enabled = false)
|
||||
public void testCorrect() {
|
||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
|
||||
binder.bindToRequest(request, ImmutableSet.of(injector.getInstance(EncryptionService.class)
|
||||
.fromHex("abddef"), injector.getInstance(EncryptionService.class).fromHex("1234")));
|
||||
assertEquals(request.getPayload().getRawContent(),
|
||||
"{\"checksums\":{\"abddef\":null,\"1234\":null}}");
|
||||
binder.bindToRequest(request, ImmutableSet.of(injector.getInstance(EncryptionService.class).fromHex("abddef"),
|
||||
injector.getInstance(EncryptionService.class).fromHex("1234")));
|
||||
assertEquals(request.getPayload().getRawContent(), "{\"checksums\":{\"abddef\":null,\"1234\":null}}");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
|
||||
|
|
|
@ -5,10 +5,11 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Client;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -29,7 +30,7 @@ public class ParseClientFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Client>>() {
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Attribute;
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.chef.domain.Metadata;
|
||||
|
@ -13,15 +14,15 @@ import org.jclouds.chef.domain.Resource;
|
|||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -37,10 +38,12 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
|
||||
private ParseJson<CookbookVersion> handler;
|
||||
private Injector injector;
|
||||
private Json json;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
json = injector.getInstance(Json.class);
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<CookbookVersion>>() {
|
||||
}));
|
||||
}
|
||||
|
@ -50,8 +53,8 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
|
||||
.toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
@ -59,8 +62,8 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/tomcat-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
|
||||
.toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
@ -68,8 +71,8 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
|
||||
.toJson(cookbook))))));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
|
|
@ -8,8 +8,8 @@ import org.jclouds.chef.config.ChefParserModule;
|
|||
import org.jclouds.chef.domain.DataBagItem;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ParseDataBagItemFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule(), new ChefParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<DataBagItem>>() {
|
||||
}));
|
||||
mapper = injector.getInstance(Gson.class);
|
||||
|
|
|
@ -4,9 +4,10 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -26,7 +27,7 @@ public class ParseKeyFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(ParseKeyFromJson.class);
|
||||
}
|
||||
|
||||
|
@ -43,8 +44,8 @@ public class ParseKeyFromJsonTest {
|
|||
}
|
||||
|
||||
public void test2() {
|
||||
String key = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseKeyFromJsonTest.class.getResourceAsStream("/newclient.txt"))));
|
||||
String key = handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(ParseKeyFromJsonTest.class
|
||||
.getResourceAsStream("/newclient.txt"))));
|
||||
assert key.startsWith("-----BEGIN RSA PRIVATE KEY-----\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public class ParseKeySetFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(ParseKeySetFromJson.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,13 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Node;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -32,16 +33,16 @@ public class ParseNodeFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Node>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
Node node = new Node("adrian-jcloudstest", ImmutableMap.<String, JsonBall> of("tomcat6",new JsonBall("{\"ssl_port\":8433}")), ImmutableMap
|
||||
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(),
|
||||
Collections.singleton("recipe[java]"));
|
||||
Node node = new Node("adrian-jcloudstest", ImmutableMap.<String, JsonBall> of("tomcat6", new JsonBall(
|
||||
"{\"ssl_port\":8433}")), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(),
|
||||
ImmutableMap.<String, JsonBall> of(), Collections.singleton("recipe[java]"));
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/node.json")))), node);
|
||||
|
|
|
@ -22,11 +22,12 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Organization;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -47,7 +48,7 @@ public class ParseOrganizationFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Organization>>() {
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -4,19 +4,17 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -35,28 +33,16 @@ public class ParseSandboxFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule(),
|
||||
new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
}
|
||||
|
||||
});
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<Sandbox>>() {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Sandbox>>() {
|
||||
}));
|
||||
dateService = injector.getInstance(DateService.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/sandbox.json")))), new Sandbox(
|
||||
"1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"),
|
||||
ImmutableSet.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(ParseSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/sandbox.json")))), new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false,
|
||||
dateService.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet.<String> of(),
|
||||
"f9d6d9b72bae465890aae87969f98a9c", "f9d6d9b72bae465890aae87969f98a9c"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.ChecksumStatus;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -36,39 +37,28 @@ public class ParseUploadSandboxFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<UploadSandbox>>() {
|
||||
injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<UploadSandbox>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
EncryptionService encryptionService = injector
|
||||
.getInstance(EncryptionService.class);
|
||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseUploadSandboxFromJsonTest.class
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(ParseUploadSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/upload-site.json")))),
|
||||
new UploadSandbox(
|
||||
URI
|
||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
||||
ImmutableMap
|
||||
.<List<Byte>, ChecksumStatus> of(
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")),
|
||||
Bytes.asList(encryptionService.fromHex("0c5ecd7788cf4f6c7de2a57193897a6c")),
|
||||
new ChecksumStatus(
|
||||
URI
|
||||
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
|
||||
true),
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("0189e76ccc476701d6b374e5a1a27347")),
|
||||
new ChecksumStatus(),
|
||||
Bytes
|
||||
.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0")),
|
||||
new ChecksumStatus()),
|
||||
true), Bytes.asList(encryptionService.fromHex("0189e76ccc476701d6b374e5a1a27347")),
|
||||
new ChecksumStatus(), Bytes.asList(encryptionService
|
||||
.fromHex("1dda05ed139664f1f89b9dec482b77c0")), new ChecksumStatus()),
|
||||
"d454f71e2a5f400c808d0c5d04c2c88c"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,12 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.User;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -30,9 +31,8 @@ public class ParseUserFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
handler = injector.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<User>>() {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<User>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ public class ParseUserFromJsonTest {
|
|||
|
||||
String toParse = "{\n\"username\": \"bobo\",\n\"first_name\": \"Bobo\",\n\"middle_name\": \"Tiberion\",\n\"last_name\": \"Clown\",\n\"display_name\": \"Bobo T. Clown\",\n\"email\": \"bobo@clownco.com\" \n}";
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(Utils.toInputStream(toParse)))), user);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(toParse)))), user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.jclouds.ohai;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.ohai.config.OhaiModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code JMX}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ohai.JMXTest")
|
||||
public class JMXTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final RuntimeMXBean runtime = createMock(RuntimeMXBean.class);
|
||||
|
||||
expect(runtime.getUptime()).andReturn(69876000l);
|
||||
|
||||
replay(runtime);
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule(), new OhaiModule() {
|
||||
@Override
|
||||
protected RuntimeMXBean provideRuntimeMXBean() {
|
||||
return runtime;
|
||||
}
|
||||
});
|
||||
Json json = injector.getInstance(Json.class);
|
||||
JMX jmx = injector.getInstance(JMX.class);
|
||||
|
||||
assertEquals(json.toJson(jmx.get()), "{\"uptime_seconds\":69876}");
|
||||
|
||||
verify(runtime);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.jclouds.ohai;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.chef.ChefClient;
|
||||
import org.jclouds.chef.domain.Node;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code UpdateNode}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ohai.UpdateNodeTest")
|
||||
public class UpdateNodeTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ChefClient chef = createMock(ChefClient.class);
|
||||
|
||||
Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of();
|
||||
|
||||
Node node = new Node("name", ImmutableSet.<String> of());
|
||||
|
||||
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
|
||||
|
||||
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap
|
||||
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of());
|
||||
|
||||
expect(chef.getNode("name")).andReturn(node);
|
||||
node.getAutomatic().putAll(automaticSupplier.get());
|
||||
expect(chef.updateNode(nodeWithAutomatic)).andReturn(null);
|
||||
|
||||
replay(chef);
|
||||
|
||||
UpdateNode updater = new UpdateNode(chef, automaticSupplier);
|
||||
|
||||
updater.updateNode("name");
|
||||
verify(chef);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.jclouds.ohai;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.ohai.config.BaseOhaiModule;
|
||||
import org.jclouds.ohai.functions.ByteArrayToMacAddress;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code WhiteListCompliantJVM}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ohai.WhiteListCompliantJVMTest")
|
||||
public class WhiteListCompliantJVMTest {
|
||||
|
||||
@Test
|
||||
public void test() throws SocketException {
|
||||
|
||||
byte[] mac = NetworkInterface.getNetworkInterfaces().nextElement().getHardwareAddress();
|
||||
final Properties sysProperties = new Properties();
|
||||
|
||||
sysProperties.setProperty("os.name", "Mac OS X");
|
||||
sysProperties.setProperty("os.version", "10.3.0");
|
||||
sysProperties.setProperty("user.name", "user");
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule(), new BaseOhaiModule() {
|
||||
@Override
|
||||
protected Long nanoTime() {
|
||||
return 1279992919325290l;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties systemProperties() {
|
||||
return sysProperties;
|
||||
}
|
||||
|
||||
});
|
||||
String macString = injector.getInstance(ByteArrayToMacAddress.class).apply(mac);
|
||||
Json json = injector.getInstance(Json.class);
|
||||
WhiteListCompliantJVM WhiteListCompliantJVM = injector.getInstance(WhiteListCompliantJVM.class);
|
||||
|
||||
assertEquals(
|
||||
json.toJson(WhiteListCompliantJVM.get()),
|
||||
"{\"ohai_time\":1279992919.32529,\"java\":{\"user.name\":\"user\",\"os.version\":\"10.3.0\",\"os.name\":\"Mac OS X\"},\"macaddress\":\""
|
||||
+ macString + "\",\"platform\":\"macosx\",\"platform_version\":\"10.3.0\",\"current_user\":\"user\"}");
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.jclouds.ohai.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ByteArrayToMacAddress}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "ohai.ByteArrayToMacAddressTest")
|
||||
public class ByteArrayToMacAddressTest {
|
||||
|
||||
private ByteArrayToMacAddress converter;
|
||||
private EncryptionService encryptionService;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector();
|
||||
converter = injector.getInstance(ByteArrayToMacAddress.class);
|
||||
encryptionService = injector.getInstance(EncryptionService.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
assertEquals(converter.apply(encryptionService.fromHex("0026bb09e6c4")), "00:26:bb:09:e6:c4");
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC.
|
||||
Copyright (C) 2010 Cloud Conscious, LLC.
|
||||
<info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
|
|
Loading…
Reference in New Issue