Skip to content

Add 'entityStatus' for v11 API #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ This client code allows you to interact with Cloudera Manager to:
* Upgrade services running on your cluster
* Access time-series data on resource utilitization for any activity in the system
* Read logs for all processes in the system as well as stdout and stderr
* Programmatically configuration all aspects of your deployment
* Programmatically configure all aspects of your deployment
* Collect diagnostic data to aid in debugging issues
* Run distributed commands to manage auto-failover, host decommissioning and more
* View all events and alerts that have occurred in the system
6 changes: 3 additions & 3 deletions java/enunciate.xml
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@
xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.27.xsd">

<api-classes>
<include pattern="com.cloudera.api.v9.*"/>
<include pattern="com.cloudera.api.v10.*"/>
</api-classes>

<services>
<rest defaultRestSubcontext="/api/v9"/>
<rest defaultRestSubcontext="/api/v10"/>
</services>

<modules>
<docs splashPackage="com.cloudera.api"
copyright="Cloudera, Inc. All rights reserved."
docsDir="apidocs"
title="Cloudera Manager API v9"
title="Cloudera Manager API v10"
groupRestResources="byPath"
freemarkerXMLProcessingTemplate="api-docs.fmt"
css="static/cms/css/api-docs.css"
4 changes: 2 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@
<groupId>com.cloudera.api</groupId>
<artifactId>cloudera-manager-api</artifactId>
<name>Cloudera Manager API</name>
<version>5.3.0</version>
<version>5.4.0</version>

<properties>
<cxf.version>2.7.5</cxf.version>
<guava.version>14.0</guava.version>
<jackson2.version>2.1.0</jackson2.version>
<joda.version>2.1</joda.version>
<junit.version>4.8.2</junit.version>
<junit.version>4.11</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<test.redirectToFile>true</test.redirectToFile>
<privateClassPath>com.cloudera.api.shaded</privateClassPath>
7 changes: 7 additions & 0 deletions java/src/main/java/com/cloudera/api/ApiRootResource.java
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
import com.cloudera.api.v7.RootResourceV7;
import com.cloudera.api.v8.RootResourceV8;
import com.cloudera.api.v9.RootResourceV9;
import com.cloudera.api.v10.RootResourceV10;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -94,6 +95,12 @@ public interface ApiRootResource {
@Path("/v9")
RootResourceV9 getRootV9();

/**
* @return The v10 root resource.
*/
@Path("/v10")
RootResourceV10 getRootV10();

/**
* Fetch the current API version supported by the server.
* <p>
117 changes: 93 additions & 24 deletions java/src/main/java/com/cloudera/api/ClouderaManagerClientBuilder.java
Original file line number Diff line number Diff line change
@@ -18,25 +18,29 @@

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.google.common.annotations.VisibleForTesting;

import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

public class ClouderaManagerClientBuilder {
public static final int DEFAULT_TCP_PORT = 7180;
public static final long DEFAULT_CONNECTION_TIMEOUT = 0;
@@ -61,6 +65,38 @@ public class ClouderaManagerClientBuilder {
private boolean validateCn = true;
private TrustManager[] trustManagers = null;

/**
* Cache JAXRSClientFactoryBean per proxyType.
*
* We need a cache because CXF stores stubs
* ({@link org.apache.cxf.jaxrs.model.ClassResourceInfo} objects) as a reference
* inside JAXRSServiceFactoryBean, which is composed within instances of
* {@link JAXRSClientFactoryBean}.
*
* This avoids:
* - creating a lot of temporaries generated during the proxy creation for
* each client
*
* - ensures that different proxies of the same type actually share the same
* ClassResourceInfo, thus reducing aggregate usage
*
* Also, as a useful side effect, generates proxies with cached proxy types faster.
*/
private static final LoadingCache<Class<?>, JAXRSClientFactoryBean>
clientStaticResources =
CacheBuilder.newBuilder()
.softValues()
.build(
new CacheLoader<Class<?>, JAXRSClientFactoryBean>(){
@Override
public JAXRSClientFactoryBean load(Class<?> proxyType) throws Exception {
JAXRSClientFactoryBean clientFactoryBean = new JAXRSClientFactoryBean();
clientFactoryBean.setResourceClass(proxyType);
clientFactoryBean.setProvider(new JacksonJsonProvider(new ApiObjectMapper()));
return clientFactoryBean;
}
});

public ClouderaManagerClientBuilder withBaseURL(URL baseUrl) {
this.baseUrl = baseUrl;
return this;
@@ -154,27 +190,40 @@ public void setTrustManagers(TrustManager[] managers) {
trustManagers = managers;
}

/**
* Build an ApiRootResource proxy object for communicating with the remote server.
* @return an ApiRootResource proxy object
*/
public ApiRootResource build() {
return build(ApiRootResource.class);
}

/**
* Build a client proxy, for a specific proxy type.
* @param proxyType proxy type class
* @return client proxy stub
*/
protected <T> T build(Class<T> proxyType) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();

String address = generateAddress();
boolean isTlsEnabled = address.startsWith("https://");
bean.setAddress(address);
if (username != null) {
bean.setUsername(username);
bean.setPassword(password);
}
if (enableLogging) {
bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
T rootResource;
// Synchronized on the class to correlate with the scope of clientStaticResources
// We want to ensure that the shared bean isn't set concurrently in multiple callers
synchronized (ClouderaManagerClientBuilder.class) {
JAXRSClientFactoryBean bean =
cleanFactory(clientStaticResources.getUnchecked(proxyType));
bean.setAddress(address);
if (username != null) {
bean.setUsername(username);
bean.setPassword(password);
}

if (enableLogging) {
bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
}
rootResource = bean.create(proxyType);
}
bean.setResourceClass(proxyType);
bean.setProvider(new JacksonJsonProvider(new ApiObjectMapper()));

T rootResource = bean.create(proxyType);
boolean isTlsEnabled = address.startsWith("https://");
ClientConfiguration config = WebClient.getConfig(rootResource);
HTTPConduit conduit = (HTTPConduit) config.getConduit();
if (isTlsEnabled) {
@@ -197,6 +246,13 @@ else if (trustManagers != null) {
return rootResource;
}

private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) {
bean.setUsername(null);
bean.setPassword(null);
bean.setFeatures(Arrays.<AbstractFeature>asList());
return bean;
}

/**
* Closes the transport level conduit in the client. Reopening a new
* connection, requires creating a new client object using the build()
@@ -215,6 +271,21 @@ public static void closeClient(ApiRootResource root) {
conduit.close();
}

/**
* Clears any cached resources shared during build operations
* across instances of this class.
*
* This includes shared proxy/stub information, that will be automatically
* garbage collected when used heap memory in the JVM
* nears max heap memory in the JVM.
*
* In general, it is unnecessary to invoke this method, unless you are
* concerned with reducing used heap memory in the JVM.
*/
public static void clearCachedResources() {
clientStaticResources.invalidateAll();
}

/** A trust manager that will accept all certificates. */
private static class AcceptAllTrustManager implements X509TrustManager {

@@ -229,7 +300,5 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) {
public X509Certificate[] getAcceptedIssuers() {
return null;
}

}

}
1 change: 1 addition & 0 deletions java/src/main/java/com/cloudera/api/model/ApiCluster.java
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import java.util.List;

/**
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@

package com.cloudera.api.model;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
@@ -31,6 +34,7 @@ public class ApiCollectDiagnosticDataArguments {
private String ticketNumber;
private String comments;
private String clusterName;
private List<String> roles;

/**
* The maximum approximate bundle size of the output file
@@ -115,4 +119,24 @@ public String getClusterName() {
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

/**
* List of roles for which to get logs and metrics.
*
* If set, this restricts the roles for log and metrics collection
* to the list specified.
*
* If empty, the default is to get logs for all roles (in the selected
* cluster, if one is selected).
*
* Introduced in API v10 of the API.
*/
@XmlElement
public List<String> getRoles() {
return roles;
}

public void setRoles(List<String> roles) {
this.roles = roles;
}
}
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public class ApiHdfsReplicationArguments {
private boolean skipChecksumChecks;
private Boolean skipTrash;
private ReplicationStrategy replicationStrategy;
private Boolean preserveXAttrs;

/**
* The strategy for distributing the file replication tasks among the mappers
@@ -224,6 +225,9 @@ public void setPreserveBlockSize(boolean preserveBlockSize) {
/**
* Whether to preserve the HDFS owner, group and permissions. Defaults to
* false.
* Starting from V10, it also preserves ACLs. Defaults to null (no preserve).
* ACLs is preserved if both clusters enable ACL support, and replication
* ignores any ACL related failures.
*/
@XmlElement
public boolean getPreservePermissions() {
@@ -284,6 +288,21 @@ public void setReplicationStrategy(ReplicationStrategy replicationStrategy) {
this.replicationStrategy = replicationStrategy;
}

/**
* Whether to preserve XAttrs, default to false
* This is introduced in V10. To preserve XAttrs, both CDH versions
* should be >= 5.2. Replication fails if either cluster does not support
* XAttrs.
*/
@XmlElement
public Boolean getPreserveXAttrs() {
return preserveXAttrs;
}

public void setPreserveXAttrs(Boolean preserveXAttrs) {
this.preserveXAttrs = preserveXAttrs;
}

@Override
public String toString() {
return Objects.toStringHelper(this)
@@ -304,6 +323,7 @@ public String toString() {
.add("skipChecksumChecks", skipChecksumChecks)
.add("skipTrash", skipTrash)
.add("replicationStrategy", replicationStrategy)
.add("preserveXAttrs", preserveXAttrs)
.toString();
}

@@ -327,7 +347,8 @@ public boolean equals(Object o) {
Objects.equal(logPath, other.getLogPath()) &&
skipChecksumChecks == other.getSkipChecksumChecks() &&
Objects.equal(skipTrash, other.getSkipTrash()) &&
Objects.equal(replicationStrategy, other.getReplicationStrategy()));
Objects.equal(replicationStrategy, other.getReplicationStrategy()) &&
Objects.equal(preserveXAttrs, other.getPreserveXAttrs()));
}

@Override
@@ -336,6 +357,7 @@ public int hashCode() {
mapreduceServiceName, schedulerPoolName, numMaps, dryRun,
bandwidthPerMap, abortOnError, removeMissingFiles,
preserveReplicationCount, preserveBlockSize, preservePermissions,
logPath, skipChecksumChecks, skipTrash, replicationStrategy);
logPath, skipChecksumChecks, skipTrash, replicationStrategy,
preserveXAttrs);
}
}
Original file line number Diff line number Diff line change
@@ -33,5 +33,5 @@ public enum ApiHealthSummary {
/** The subject is in concerning health */
CONCERNING,
/** The subject is in bad health */
BAD
BAD;
}
Original file line number Diff line number Diff line change
@@ -141,6 +141,15 @@ public void setPassword(String password) {
/**
* The private key to authenticate with the hosts.
* Specify either this or a password.
* <br>
* The private key, if specified, needs to be a
* standard PEM-encoded key as a single string, with all line breaks
* replaced with the line-feed control character '\n'.
* <br>
* A value will typically look like the following string:
* <br>
* -----BEGIN RSA PRIVATE KEY-----\n[base-64 encoded key]\n-----END RSA PRIVATE KEY-----
* <br>
*/
@XmlElement
public String getPrivateKey() {
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.model;

import com.cloudera.api.ApiUtils;

import com.google.common.base.Objects;

import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="migrateRolesArgs")
public class ApiMigrateRolesArguments {

private List<String> roleNamesToMigrate;
private String destinationHostId;
private boolean clearStaleRoleData;

/**
* The list of role names to migrate.
*/
@XmlElement
public List<String> getRoleNamesToMigrate() {
return roleNamesToMigrate;
}

public void setRoleNamesToMigrate(List<String> roleNamesToMigrate) {
this.roleNamesToMigrate = roleNamesToMigrate;
}

/**
* The ID of the host to which the roles should be migrated.
*/
@XmlElement
public String getDestinationHostId() {
return destinationHostId;
}

public void setDestinationHostId(String destinationHostId) {
this.destinationHostId = destinationHostId;
}

/**
* Delete existing stale role data, if any. For example, when migrating
* a NameNode, if the destination host has stale data in the NameNode data
* directories (possibly because a NameNode role was previously located
* there), this stale data will be deleted before migrating the role.
*/
@XmlElement
public boolean getClearStaleRoleData() {
return clearStaleRoleData;
}

public void setClearStaleRoleData(boolean clearStaleRoleData) {
this.clearStaleRoleData = clearStaleRoleData;
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("roleNamesToMigrate", roleNamesToMigrate)
.add("destinationHostId", destinationHostId)
.add("clearStaleRoleData", clearStaleRoleData)
.toString();
}

@Override
public int hashCode() {
return Objects.hashCode(
roleNamesToMigrate,
destinationHostId,
clearStaleRoleData);
}

@Override
public boolean equals(Object o) {
ApiMigrateRolesArguments that = ApiUtils.baseEquals(this, o);
return this == that || (that != null
&& Objects.equal(this.roleNamesToMigrate, that.roleNamesToMigrate)
&& Objects.equal(this.destinationHostId, that.destinationHostId)
&& Objects.equal(this.clearStaleRoleData, that.clearStaleRoleData));
}
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,10 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Rolling upgrade arguments used in the CDH Upgrade Command. Part of
* ApiCdhUpgradeArgs.
*/
@XmlRootElement(name = "rollingUpgradeClusterArgs")
public class ApiRollingUpgradeClusterArgs {

@@ -41,7 +45,7 @@ public Integer getSlaveBatchSize() {
return slaveBatchSize;
}

public void setSlaveBatchSize(int slaveBatchSize) {
public void setSlaveBatchSize(Integer slaveBatchSize) {
this.slaveBatchSize = slaveBatchSize;
}

@@ -55,7 +59,7 @@ public Integer getSleepSeconds() {
return sleepSeconds;
}

public void setSleepSeconds(int sleepSeconds) {
public void setSleepSeconds(Integer sleepSeconds) {
this.sleepSeconds = sleepSeconds;
}

@@ -73,7 +77,7 @@ public Integer getSlaveFailCountThreshold() {
return slaveFailCountThreshold;
}

public void setSlaveFailCountThreshold(int slaveFailCountThreshold) {
public void setSlaveFailCountThreshold(Integer slaveFailCountThreshold) {
this.slaveFailCountThreshold = slaveFailCountThreshold;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.model;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.cloudera.api.ApiUtils;
import com.google.common.base.Objects;

/**
* Arguments used for Rolling Upgrade command.
*/
@XmlRootElement(name="rollingUpgradeServicesArgs")
public class ApiRollingUpgradeServicesArgs {

private Integer slaveBatchSize;
private Integer sleepSeconds;
private Integer slaveFailCountThreshold;
private String upgradeFromCdhVersion;
private String upgradeToCdhVersion;
private List<String> upgradeServiceNames;

/**
* Current CDH Version of the services. Example versions are:
* "5.1.0", "5.2.2" or "5.4.0"
*/
@XmlElement
public String getUpgradeFromCdhVersion() {
return upgradeFromCdhVersion;
}

public void setUpgradeFromCdhVersion(String upgradeFromCdhVersion) {
this.upgradeFromCdhVersion = upgradeFromCdhVersion;
}

/**
* Target CDH Version for the services. The CDH version should already
* be present and activated on the nodes. Example versions are:
* "5.1.0", "5.2.2" or "5.4.0"
*/
@XmlElement
public String getUpgradeToCdhVersion() {
return upgradeToCdhVersion;
}

public void setUpgradeToCdhVersion(String upgradeToCdhVersion) {
this.upgradeToCdhVersion = upgradeToCdhVersion;
}

/**
* Number of hosts with slave roles to upgrade at a time.
* Must be greater than zero. Default is 1.
*/
@XmlElement
public Integer getSlaveBatchSize() {
return slaveBatchSize;
}

public void setSlaveBatchSize(Integer slaveBatchSize) {
this.slaveBatchSize = slaveBatchSize;
}

/**
* Number of seconds to sleep between restarts of slave host batches.
*
* Must be greater than or equal to 0. Default is 0.
*/
@XmlElement
public Integer getSleepSeconds() {
return sleepSeconds;
}

public void setSleepSeconds(Integer sleepSeconds) {
this.sleepSeconds = sleepSeconds;
}

/**
* The threshold for number of slave host batches that are allowed to fail
* to restart before the entire command is considered failed.
*
* Must be greater than or equal to 0. Default is 0.
* <p>
* This argument is for ADVANCED users only.
* </p>
*/
@XmlElement
public Integer getSlaveFailCountThreshold() {
return slaveFailCountThreshold;
}

public void setSlaveFailCountThreshold(Integer slaveFailCountThreshold) {
this.slaveFailCountThreshold = slaveFailCountThreshold;
}

/**
* List of services to upgrade.
* Only the services that support rolling upgrade should be included.
*/
@XmlElement
public List<String> getUpgradeServiceNames() {
return upgradeServiceNames;
}

public void setUpgradeServiceNames(List<String> upgradeServiceNames) {
this.upgradeServiceNames = upgradeServiceNames;
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("slaveBatchSize", slaveBatchSize)
.add("slaveFailCountThreshold", slaveFailCountThreshold)
.add("sleepSeconds", sleepSeconds)
.add("upgradeFromCdhVersion", upgradeFromCdhVersion)
.add("upgradeToCdhVersion", upgradeToCdhVersion)
.add("upgradeServiceNames", upgradeServiceNames)
.toString();
}

@Override
public boolean equals(Object o) {
ApiRollingUpgradeServicesArgs other = ApiUtils.baseEquals(this, o);
return this == other || (other != null &&
Objects.equal(slaveBatchSize, other.slaveBatchSize) &&
Objects.equal(slaveFailCountThreshold, other.slaveFailCountThreshold) &&
Objects.equal(sleepSeconds, other.sleepSeconds) &&
Objects.equal(upgradeFromCdhVersion, other.upgradeFromCdhVersion) &&
Objects.equal(upgradeToCdhVersion, other.upgradeToCdhVersion) &&
Objects.equal(upgradeServiceNames, other.upgradeServiceNames));
}

@Override
public int hashCode() {
return Objects.hashCode(slaveBatchSize, slaveFailCountThreshold, sleepSeconds,
upgradeFromCdhVersion, upgradeToCdhVersion, upgradeServiceNames);
}
}
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
@XmlRootElement(name = "yarnApplicationDiagnosticsCollectionArgs")
public class ApiYarnApplicationDiagnosticsCollectionArgs {
private List<String> applicationIds;
private String ticketNumber;
private String comments;

/**
* Id's of the applications whose diagnostics data has to be collected
@@ -38,4 +40,28 @@ public List<String> getApplicationIds() {
public void setApplicationIds(List<String> applicationIds) {
this.applicationIds = applicationIds;
}

/**
* Ticket Number of the Cloudera Support Ticket
*/
@XmlElement
public String getTicketNumber() {
return ticketNumber;
}

public void setTicketNumber(String ticketNumber) {
this.ticketNumber = ticketNumber;
}

/**
* Comments to add to the support bundle
*/
@XmlElement
public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}
}
261 changes: 261 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/AuditsResourceV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// Copyright (c) 2014 Cloudera, Inc. All rights reserved.
package com.cloudera.api.v10;

import com.cloudera.api.v8.AuditsResourceV8;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import static com.cloudera.api.Parameters.DATE_TIME_NOW;
import static com.cloudera.api.Parameters.QUERY;

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })

/**
* Fetches and streams the requested audit events.
* <p>
* By default, this call will fetch the first 100 audit events (sorted from most
* recent to oldest) corresponding to a 1 day window based on provided end time
* (which defaults to the current CM server time). The <em>startTime</em> and
* <em>endTime</em> parameters can be used to control the window being queried.
* <p>
* Audit events for CM managed services are only retrieved if Cloudera
* Navigator server is running.
*
* @param maxResults Maximum number of audits to return
* @param resultOffset Offset of audits to return
* @param startTime Start of the period to query (defaults to 1 day ago
* relative to endTime)
* @param endTime End of the period to query (defaults to current time)
* @param query
* The query to filter out audits in the system. It accepts
* querying the intersection of a list of constraints,
* joined together with semicolons (without spaces). For example:
* </p>
* <dl>
* <dt>command==listStatus</dt>
* <dd>looks for audits with listStatus command.</dd>
* <dt>command==listStatus;username!=foo</dt>
* <dd>looks for audits with listStatus command but excludes
* audits generated by foo username</dd>
* <dt>command==listStatus;source==*oozie*</dt>
* <dd>looks for audits with listStatus command and source that
* contains the string 'oozie'.
* </dd>
* </dl>
*
* Following are valid selectors for the query (if applicable to the
* audit):
* <table>
* <tr>
* <th> Selector </th>
* <th> Description </th>
* <th> SCM </th>
* <th> HDFS </th>
* <th> HBase </th>
* <th> Hive </th>
* <th> Impala </th>
* <th> Sentry </th>
* </tr>
* <tr>
* <td> service </td>
* <td> Cloudera Manager Service </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> operation </td>
* <td> Operation name </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> username </td>
* <td> User name </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> impersonator</td>
* <td> Impersonator </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> ip_address </td>
* <td> IP Address </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> allowed </td>
* <td> Whether the request was allowed or denied </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> qualifier</td>
* <td> Column qualifier </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> </td>
* <td> </td>
* <td> </td>
* </tr>
* <tr>
* <td> source </td>
* <td> Source resource of the operation </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> </td>
* </tr>
* <tr>
* <td> destination </td>
* <td> Destination resource of the operation </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> </td>
* </tr>
* <tr>
* <td> hostIpAddress </td>
* <td> Host IP Address </td>
* <td> x </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> </td>
* </tr>
* <tr>
* <td> role </td>
* <td> Cloudera Manager Role </td>
* <td> x </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> </td>
* </tr>
* <tr>
* <td> family </td>
* <td> Column family </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> </td>
* <td> </td>
* <td> </td>
* </tr>
* <tr>
* <td> database_name </td>
* <td> Database name </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> table_name </td>
* <td> Table name </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> object_type </td>
* <td> Type of object being handled </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* <tr>
* <td> operation_text </td>
* <td> Command/query text </td>
* <td> </td>
* <td> </td>
* <td> </td>
* <td> x </td>
* <td> x </td>
* <td> x </td>
* </tr>
* </table>
* <p>
* The only supported operator is <em>";"</em> (Boolean AND). Boolean OR is
* not supported.
* <p>
* The supported comparators are <em>==</em> and <em>!=</em>
* Note that "LIKE" comparison is supported using the wild card syntax,
* for example <em>foo==*value*</em>. Asterisk is interpreted as a wild
* card character and must not be part of the value. (LIKE comparison
* queries are converted to standard SQL LIKE syntax, so any % (%25)
* character in a value that also contains a wild card will be
* interpreted as a wild card.)
* <p>
* Values for time related query parameters (<em>startTime</em> and
* <em>endTime</em>) should be ISO8601 timestamps.
* <p/>
*
* @return List of audits in descending order of timestamp
*/
public interface AuditsResourceV10 extends AuditsResourceV8 {

@GET
@Path("/stream")
public StreamingOutput streamAudits(
@QueryParam(value = "maxResults")
@DefaultValue("100") Integer maxResults,
@QueryParam(value = "resultOffset")
@DefaultValue("0") Integer resultOffset,
@QueryParam("startTime")
String startTime,
@QueryParam("endTime")
@DefaultValue(DATE_TIME_NOW)
String endTime,
@QueryParam(QUERY) String query);
}
68 changes: 68 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/ClustersResourceV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.v10;

import static com.cloudera.api.Parameters.CLUSTER_NAME;

import com.cloudera.api.model.ApiCommand;
import com.cloudera.api.model.ApiRollingUpgradeServicesArgs;
import com.cloudera.api.v9.ClustersResourceV9;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public interface ClustersResourceV10 extends ClustersResourceV9 {

/**
* @return The services resource handler.
*/
@Override
@Path("/{clusterName}/services")
public ServicesResourceV10 getServicesResource(
@PathParam(CLUSTER_NAME) String clusterName);

/**
* Command to do a rolling upgrade of specific services in the given cluster
*
* This command does not handle any services that don't support rolling
* upgrades. The command will throw an error and not start if upgrade of any
* such service is requested.
*
* This command does not upgrade the full CDH Cluster. You should normally
* use the upgradeCDH Command for upgrading the cluster. This is primarily
* helpful if you need to need to recover from an upgrade failure or for
* advanced users to script an alternative to the upgradeCdhCommand.
*
* This command expects the binaries to be available on hosts and activated.
* It does not change any binaries on the hosts.
*
* @param clusterName The name of the cluster.
* @param args Arguments for the rolling upgrade command.
* @return Information about the submitted command.
*/
@POST
@Consumes
@Path("/{clusterName}/commands/rollingUpgrade")
public ApiCommand rollingUpgrade(
@PathParam(CLUSTER_NAME) String clusterName,
ApiRollingUpgradeServicesArgs args);
}
70 changes: 70 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/HostsResourceV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.v10;

import static com.cloudera.api.Parameters.HOST_ID;

import com.cloudera.api.model.ApiCommand;
import com.cloudera.api.model.ApiMigrateRolesArguments;
import com.cloudera.api.v2.HostsResourceV2;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public interface HostsResourceV10 extends HostsResourceV2 {

/**
* Migrate roles to a different host.
* <p>
* This command applies only to HDFS NameNode, JournalNode, and Failover
* Controller roles. In order to migrate these roles:
* <ul>
* <li>HDFS High Availability must be enabled, using quorum-based storage.</li>
* <li>HDFS must not be configured to use a federated nameservice.</li>
* </ul>
* <b>Migrating a NameNode or JournalNode role requires cluster downtime</b>.
* HDFS, along with all of its dependent services, will be stopped at the
* beginning of the migration process, and restarted at its conclusion.
* <p>If the active NameNode is selected for migration, a manual failover
* will be performed before the role is migrated. The role will remain in
* standby mode after the migration is complete.
* <p>When migrating a NameNode role, the co-located Failover Controller
* role must be migrated as well if automatic failover is enabled. The
* Failover Controller role name must be included in the list of role
* names to migrate specified in the arguments to this command (it will
* not be included implicitly). This command does not allow a Failover
* Controller role to be moved by itself, although it is possible to move
* a JournalNode independently.
* <p>
* Available since API v10.
*
* @param hostId The ID of the host on which the roles to migrate currently
* reside
* @param args Arguments for the command.
* @return Information about the submitted command.
*/
@POST
@Path("/{hostId}/commands/migrateRoles")
public ApiCommand migrateRoles(@PathParam(HOST_ID) String hostId,
ApiMigrateRolesArguments args);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.v10;

import com.cloudera.api.model.ApiBulkCommandList;
import com.cloudera.api.model.ApiRoleNameList;
import com.cloudera.api.v8.RoleCommandsResourceV8;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public interface RoleCommandsResourceV10 extends RoleCommandsResourceV8 {
/**
* Refresh a role's data.
* <p>
* For MapReduce services, this command should be executed on JobTracker
* roles. It refreshes the role's queue and node information.
* <p>
* For HDFS services, this command should be executed on NameNode or
* DataNode roles. For NameNodes, it refreshes the role's node list.
* For DataNodes, it refreshes the role's data directory list.
* <p>
* For YARN services, this command should be executed on ResourceManager
* roles. It refreshes the role's queue and node information.
* <p>
* Available since API v1. DataNode data directories refresh available
* since API v10.
*
* @param roleNames The names of the roles.
* @return A list of submitted commands.
*/
@POST
@Path("/refresh")
public ApiBulkCommandList refreshCommand(
ApiRoleNameList roleNames);
}
46 changes: 46 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/RootResourceV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.v10;

import com.cloudera.api.v9.RootResourceV9;

import javax.ws.rs.Path;

@Path("")
public interface RootResourceV10 extends RootResourceV9 {

/**
* @return The clusters resource handler.
*/
@Override
@Path("/clusters")
public ClustersResourceV10 getClustersResource();

/**
* @return The hosts resource handler.
*/
@Override
@Path("/hosts")
public HostsResourceV10 getHostsResource();

/**
* @return Audits resource handler.
*/
@Override
@Path("/audits")
public AuditsResourceV10 getAuditsResource();

}
118 changes: 118 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/ServicesResourceV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.api.v10;

import static com.cloudera.api.Parameters.SERVICE_NAME;

import com.cloudera.api.model.ApiCommand;
import com.cloudera.api.v8.ServicesResourceV8;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public interface ServicesResourceV10 extends ServicesResourceV8 {

/**
* @return The role command resource handler.
*/
@Override
@Path("/{serviceName}/roleCommands")
public RoleCommandsResourceV10 getRoleCommandsResource(
@PathParam(SERVICE_NAME) String serviceName);

/**
* Runs Hue's dumpdata command.
*
* Available since API v10.
*
* @param serviceName The name of the service
* @return Information about the submitted command.
*/
@POST
@Path("/{serviceName}/commands/hueDumpDb")
public ApiCommand hueDumpDbCommand(
@PathParam(SERVICE_NAME) String serviceName);

/**
* Runs Hue's loaddata command.
*
* Available since API v10.
*
* @param serviceName The name of the service
* @return Information about the submitted command.
*/
@POST
@Path("/{serviceName}/commands/hueLoadDb")
public ApiCommand hueLoadDbCommand(
@PathParam(SERVICE_NAME) String serviceName);

/**
* Runs Hue's syncdb command.
*
* Available since API v10.
*
* @param serviceName The name of the service
* @return Information about the submitted command.
*/
@POST
@Path("/{serviceName}/commands/hueSyncDb")
public ApiCommand hueSyncDbCommand(
@PathParam(SERVICE_NAME) String serviceName);

/**
* Create the Oozie Server Database. Only works with embedded postgresql
* database.
* <p>
* This command is to be run whenever a new user and database need to be
* created in the embedded postgresql database for an Oozie service. This
* command should usually be followed by a call to createOozieDb.
* <p>
* Available since API v10.
*
* @param serviceName
* Name of the Oozie service on which to run the command.
* @return Information about the submitted command
*/
@POST
@Consumes()
@Path("/{serviceName}/commands/oozieCreateEmbeddedDatabase")
public ApiCommand oozieCreateEmbeddedDatabaseCommand(
@PathParam(SERVICE_NAME) String serviceName);

/**
* Create the Sqoop2 Server Database tables.
* <p>
* This command is to be run whenever a new database has been specified. Will
* do nothing if tables already exist. Will not perform an upgrade. Only
* available when Sqoop2 Server is stopped.
* <p>
* Available since API v10.
*
* @param serviceName Name of the Sentry service on which to run the command.
* @return Information about the submitted command
*/
@POST
@Consumes()
@Path("/{serviceName}/commands/sqoopCreateDatabaseTables")
public ApiCommand sqoopCreateDatabaseTablesCommand(
@PathParam(SERVICE_NAME) String serviceName);
}
21 changes: 21 additions & 0 deletions java/src/main/java/com/cloudera/api/v10/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to Cloudera, Inc. under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Cloudera, Inc. 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.

/**
* API version 10, introduced in Cloudera Manager 5.4.0.
*/

package com.cloudera.api.v10;
Original file line number Diff line number Diff line change
@@ -80,6 +80,10 @@ public ApiDeployment getDeployment(
* all changes will be rolled back leaving the system exactly as it was
* before calling this method. The system will never be left in a state
* where part of the deployment is created and other parts are not.
* <p/>
* If the submitted deployment contains entities that require Cloudera
* Enterprise license, then the license should be provided to Cloudera Manager
* before making this API call.
*
* @param deployment The deployment to create
* @param deleteCurrentDeployment If true, the current deployment is deleted
2 changes: 1 addition & 1 deletion java/src/main/java/com/cloudera/api/v2/RootResourceV2.java
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public interface RootResourceV2 extends RootResourceV1 {
public ClouderaManagerResourceV2 getClouderaManagerResource();

/**
* @return The clusters resource handler.
* @return The hosts resource handler.
*/
@Override
@Path("/hosts")
Original file line number Diff line number Diff line change
@@ -129,6 +129,8 @@ public ApiCommand hdfsCreateTmpDir(

/**
* Creates the Oozie Database Schema in the configured database.
* This command does not create database. This command creates only tables
* required by Oozie. To create database, please refer to oozieCreateEmbeddedDatabase()
*
* <p>
* Available since API v2.
8 changes: 4 additions & 4 deletions java/src/main/java/com/cloudera/api/v8/AuditsResourceV8.java
Original file line number Diff line number Diff line change
@@ -38,10 +38,10 @@ public interface AuditsResourceV8 extends AuditsResource {
* Fetch audit events from Cloudera Manager (CM) and CM managed services
* like HDFS, HBase, Impala, Hive, and Sentry.
* <p>
* By default, this call will fetch all audit events corresponding to a
* 1 day window based on provided end time (which defaults to the current
* CM server time). The <em>startTime</em> and <em>endTime</em> parameters
* can be used to control the window being queried.
* By default, this call will fetch the first 100 audit events (sorted from most
* recent to oldest) corresponding to a 1 day window based on provided end time
* (which defaults to the current CM server time). The <em>startTime</em> and
* <em>endTime</em> parameters can be used to control the window being queried.
* <p>
* Audit events for CM managed services are only retrieved if Cloudera
* Navigator server is running.
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import java.net.URL;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

public class ClouderaManagerClientBuilderTest {
@@ -75,4 +76,24 @@ public void testURLGeneration() throws MalformedURLException {
// expected
}
}

@Test
public void testResourceConfig() {
ClouderaManagerClientBuilder builder = new ClouderaManagerClientBuilder();
ApiRootResource a = newProxy(builder);
assertNotNull(a);
ApiRootResource b = newProxy(builder);
assertNotNull(b);

ClouderaManagerClientBuilder.clearCachedResources();
// test after clear
assertNotNull(newProxy(builder));
}

public ApiRootResource newProxy(ClouderaManagerClientBuilder builder) {
return builder.withHost("localhost")
.withPort(1)
.enableLogging()
.build();
}
}
2 changes: 2 additions & 0 deletions java/src/test/java/com/cloudera/api/model/ApiModelTest.java
Original file line number Diff line number Diff line change
@@ -926,6 +926,7 @@ private ApiHdfsReplicationArguments newHdfsReplicationArguments() {
hdfsArgs.setLogPath("log1");
hdfsArgs.setSkipChecksumChecks(true);
hdfsArgs.setSkipTrash(true);
hdfsArgs.setPreserveXAttrs(true);
hdfsArgs.setReplicationStrategy(ReplicationStrategy.DYNAMIC);
return hdfsArgs;
}
@@ -965,6 +966,7 @@ private ApiCluster newCluster() {
cluster.setMaintenanceMode(true);
cluster.setName("mycluster");
cluster.setDisplayName("mycluster-displayName");
cluster.setClusterUrl("http://some-url:7180/cmf/clusterRedirect/mycluster");
cluster.setVersion(ApiClusterVersion.CDH4);
cluster.setFullVersion("4.1.2");
return cluster;
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
dist/
doc/
*.egg-info/
.git-hash

10 changes: 10 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -14,10 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

DOCDIR ?= doc

.PHONY: help
help:
@echo 'The build targets are:'
@echo ' dist : Create a source distribution tarball'
@echo ' test : Run unit tests'
@echo ' doc : Generate epydoc format documentation'
@echo ' clean : Clean up all generated files'

.PHONY: test
test:
@@ -33,5 +38,10 @@ dist: test
clean:
rm -rf *.egg-info
rm -rf dist
rm -rf doc
rm -rf build
find . -name *.py[co] -exec rm -f {} \;

.PHONY: doc
doc:
epydoc -v --html -o $(DOCDIR) -n python-cm_api `find src -name "*.py"`
5 changes: 3 additions & 2 deletions python/examples/timeseries.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@


"""
Given a query amd an optional time range, show all timeseries
Given a query and an optional time range, show all timeseries
data that matches the given query in the given time range.
Usage: %s [options] query
@@ -69,14 +69,15 @@
CM_HOST = 'localhost'
CM_USER = 'admin'
CM_PASSWD = 'admin'
CM_USE_TLS = False

LOG = logging.getLogger(__name__)

class TimeSeriesQuery(object):
"""
"""
def __init__(self):
self._api = ApiResource(CM_HOST, username=CM_USER, password=CM_PASSWD)
self._api = ApiResource(CM_HOST, username=CM_USER, password=CM_PASSWD, use_tls=CM_USE_TLS)

def query(self, query, from_time, to_time):
return self._api.query_timeseries(query, from_time, to_time)
4 changes: 4 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@
if platform == 'darwin':
install_requires += ['readline']

# Optional PySocks support
extras_require = dict(Socks=['PySocks >= 1.5.0'])

setup(
name = 'cm_api',
version = '10.0.0', # Compatible with API v10 (CM 5.4)
@@ -43,6 +46,7 @@
# Project uses simplejson, so ensure that it gets installed or upgraded
# on the target machine
install_requires = install_requires,
extras_require = extras_require,

author = 'Cloudera, Inc.',
author_email = 'scm-users@cloudera.org',
5 changes: 3 additions & 2 deletions python/src/cm_api/endpoints/cms.py
Original file line number Diff line number Diff line change
@@ -201,9 +201,10 @@ def collect_diagnostic_data_45(self, end_datetime, bundle_size_bytes, cluster_na
args = {
'endTime': end_datetime.isoformat(),
'bundleSizeBytes': bundle_size_bytes,
'clusterName': cluster_name,
'roles': roles
'clusterName': cluster_name
}
if self._get_resource_root().version >= 10:
args['roles'] = roles
return self._cmd('collectDiagnosticData', data=args)

def hosts_decommission(self, host_names):
1 change: 1 addition & 0 deletions python/src/cm_api/endpoints/roles.py
Original file line number Diff line number Diff line change
@@ -116,6 +116,7 @@ class ApiRole(BaseApiResource):
'configStale' : ROAttr(),
'configStalenessStatus' : ROAttr(),
'haStatus' : ROAttr(),
'entityStatus' : ROAttr(),
'roleUrl' : ROAttr(),
'commissionState' : ROAttr(),
'maintenanceMode' : ROAttr(),
13 changes: 13 additions & 0 deletions python/src/cm_api/http_client.py
Original file line number Diff line number Diff line change
@@ -14,11 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import cookielib
import logging
import posixpath
import types
import urllib

try:
import socks
import socket
socks_server = os.environ.get("SOCKS_SERVER", None)
if socks_server:
host, port = socks_server.split(":")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
socket.socket = socks.socksocket
except ImportError:
pass

import urllib2

__docformat__ = "epytext"
10 changes: 10 additions & 0 deletions python/src/cm_api/resource.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
try:
import json
except ImportError:
@@ -22,6 +23,15 @@
import posixpath
import time
import socket
try:
import socks
socks_server = os.environ.get("SOCKS_SERVER", None)
if socks_server:
host, port = socks_server.split(":")
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
socket.socket = socks.socksocket
except ImportError:
pass
import urllib2

LOG = logging.getLogger(__name__)
6 changes: 5 additions & 1 deletion python/src/cm_api_tests/test_yarn.py
Original file line number Diff line number Diff line change
@@ -15,13 +15,17 @@
# limitations under the License.

import datetime
import json
import unittest
from cm_api.endpoints.clusters import *
from cm_api.endpoints.services import *
from cm_api.endpoints.types import *
from cm_api_tests import utils

try:
import json
except ImportError:
import simplejson as json

class TestYarn(unittest.TestCase):

def test_get_yarn_applications(self):
5 changes: 3 additions & 2 deletions python/src/cm_shell/cmps.py
Original file line number Diff line number Diff line change
@@ -593,6 +593,7 @@ def main():
parser.add_argument('--password', action='store', dest='password')
parser.add_argument('-e', '--execute', action='store', dest='execute')
parser.add_argument('-s', '--seperator', action='store', dest='seperator')
parser.add_argument('-t', '--tls', action='store_const', dest='use_tls', const=True, default=False)
args = parser.parse_args()

# Check if a username was suplied, if not, prompt the user
@@ -605,12 +606,12 @@ def main():

# Attempt to authenticate using the API
global api
api = ApiResource(args.hostname, args.port, args.username, args.password)
api = ApiResource(args.hostname, args.port, args.username, args.password, args.use_tls)
try:
api.echo("ping")
except ApiException:
try:
api = ApiResource(args.hostname, args.port, args.username, args.password, version=1)
api = ApiResource(args.hostname, args.port, args.username, args.password, args.use_tls, version=1)
api.echo("ping")
except ApiException:
print("Unable to Authenticate")