Giter VIP home page Giter VIP logo

oneview-sdk-java's Introduction

HPE OneView SDK for Java

The HPE OneView SDK for Java enables Java developers to easily integrate their Java solutions with the HPE OneView. You can get started in minutes downloading, and building the project using the Maven project management tool, or by adding the SDK as a dependency of the Maven project.

The SDK provides clients for the REST API specification of each resource type available in the HPE OneView.

The project Javadocs are available at http://hewlettpackard.github.io/oneview-sdk-java/

Getting Started

Minimum requirements

  • Java 1.7
  • Maven 3.0.5
  • OpenSSL

Add SDK as Maven dependency

The SDK is available in the Apache Maven Central Repository (formely known as Maven Central). Thus, the recommended way to use the OneView SDK for Java in your project is to consume it from Maven. You can add the HPE OneView Java SDK as a dependency of your project, by adding the following lines to your pom.xml:

<dependency>
  <groupId>com.hpe.oneview</groupId>
  <artifactId>oneview-sdk-java</artifactId>
  <version>3.2.1</version>
</dependency>

Building from source

Once you check out the code from GitHub, you can build the SDK using Maven. To build the project from its source, you can use the following commands:

$ git clone [email protected]:HewlettPackard/oneview-sdk-java.git
$ mvn -f oneview-sdk-java/pom.xml clean install

Generate TrustStore to store SSL server certificate

To enable the SDK to establish a SSL connection to the HPE OneView server, it is necessary to generate a TrustStore file containing the server credentials.

Use the following steps to perform this task:

1. Fetch server CA certificate

Example:

$ openssl s_client -showcerts -host <host> -port 443

Copy the server certificate content from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE----- (inclusive). Paste the content into a file called default-server.crt.

2. Generate TrustStore

Example:

$ keytool -import -v -trustcacerts -alias myservercert -file default-server.crt -keystore TrustStore

Note: Choose yes option, when prompted to trust the certificate.

Inside the project's bin folder you can find a bash script (build-truststore.sh) that can be used to automate the creation of the TrustStore file. It can also serve as a reference, if you decide to run the commands manually.

3. Image Streamer

To use the SDK with an Image Streamer, add the Image Streamer certificate in the generated TrustStore file. For that, repeat the previous steps pointing to the Image Streamer appliance.

Example:

$ openssl s_client -showcerts -host <image_streamer_host> -port 443

Example:

$ keytool -import -v -trustcacerts -alias myservercert -file default-server.crt -keystore TrustStore

Note: Choose yes option, when prompted to trust the certificate.

Setting your OneView version

The OneView Java SDK supports the API endpoints 120, 200, 201, 300, 500 (partially). The current default API version used by the Java SDK is 300.

To change the API to execute the samples, you must set the API version on the sdk-config-sample.properties:

oneview.api_version=500

The API list is as follows:

  • HPE OneView 1.20 API version: 120
  • HPE OneView 2.00 API version: 200
  • HPE OneView 3.00 API version: 300
  • HPE OneView 3.10 API version: 500

Example programs

The SDK comes with several sample programs inside the samples module. For each of the supported resource types, there is a corresponding sample file. To run one of them, we recommend using an IDE (Eclipse or IntelliJ).

Note: If you choose to use Eclipse IDE, you can optionally generate the Eclipse IDE files (\*.classpath, \*.project, \*.wtpmodules and the .settings folder). You can generate these files using the Maven Eclipse Plugin with the command mvn clean eclipse:clean eclipse:eclipse.

The file oneview_java_sdk_config.properties must be updated to contain the following information:

  • Path for the TrustStore file and its password
  • OneView credentials and host information

Note: Instead of changing the location of your TrustStore file, you can just place it inside the following directory samples/src/main/resources.

Message Bus samples

Before running the Message Bus samples, it is necessary to execute a HTTP POST request to the OneView server to generate the RabbitMQ certificate files. The following example illustrates how you can perform this:

$ curl -X POST -H "Auth:{AUTHORIZATION_TOKEN}" \
-H "X-Api-Version:{VERSION}" \
-H "Content-Type:application/json" \
-d '{"commonName":"default","type":"RabbitMqClientCertV2"}' \
-k https://{HOST}/rest/certificates/client/rabbitmq

API Implementation

The status for the HPE OneView REST interfaces that have been implemented in this Java library can be found in the endpoints-support.md.

SDK Logging Configuration

For logging, the OneView SDK for Java uses the Simple Logging Facade for Java (SLF4J). The SLF4J serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j. SLF4J allows the end-user to plug in the desired logging framework at deployment time.

We highly recommend that you read the SLF4J user manual to understand how to use one of the "SLF4J bindings" to configure the SDK logs.

For example, the samples module uses the log4j as the underlying logging framework. To do this, we simply declare org.slf4j:slf4j-log4j12 as a dependency in the pom.xml file as shown in the following example:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.21</version>
</dependency>

Contributing

You know the drill. Fork it, branch it, change it, commit it, and pull-request it. We are passionate about improving this project, and are glad to accept help to make it better. However, keep the following in mind:

We reserve the right to reject changes that we feel do not fit the scope of this project. For feature additions, please open an issue to discuss your ideas before doing the work.

Naming Convention for OneView Resources

The following summarizes code structure and naming conventions for the Java SDK.

  • Packages: The package is named according to the HPE OneView API Reference group, with all characters in lowercase, separated by dots, as the standard Java package naming convention. For example: com.hp.ov.sdk.rest.client.networking.
  • Classes: We are using camel case to define the class name. For example: FcNetwork.java.
  • Client classes: Clients are named using the format <ClassName>Client.java. For example: FcNetworkClient.java.
  • Examples: Samples are named using the format <ClassNameClient>Sample.java. For example: FcNetworkClientSample.java.
  • Tests: The unit tests are named using the format <ClassNameClient>Test.java. For example: FcNetworkClientTest.java.

Testing

When contributing code to this project, we require tests to accompany the code being delivered. That ensures a higher standard of quality, and also helps to avoid minor mistakes and future regressions.

Unit Tests

To write unit tests we use JUnit and Mockito.

It is important that all methods implemented in SDK should have a correspondent test method. Method names should start with should.

To execute unit tests for a class, just run it as JUnit Test.

BDD (Behavior Driven Development) Tests

We are using Cucumber as the BDD framework to develop functional tests.

The test artifacts are located in the Automated Test Folder.

There are 2 test suites that are responsible for executing tests for all the resources implemented. One for C7000 AllTestsC7000.java and the other one is for Synergy AllTestsSynergy.java.

To execute the test suite, just run it as JUnit Test.

Test scenarios are described in .feature files, for example fcNetwork.feature.

The tests are independent among resources, so it is possible to test a single resource. To execute the FC Network test scenarios, for example, just run FcNetworkBDDTest.java as a JUnit Test.

Note: BDD tests cover OneView resources supported (not including Image Streamer resources) and can be run against real hardware or using a DCS.

For more information about requirements please check the comments in the test suite files.

Setting configuration properties for tests

There are 2 .properties files required to execute BDD tests:

This file has the same properties found in sdk-config-sample.properties used for samples. You should set attributes as TrustStore, OneView credentials, and the API version:

truststore.file=src/main/resources/TrustStore
oneview.api_version=300
oneview.hostname=10.10.10.10
oneview.username=administrator
oneview.password=admin
oneview.domain=local

This file has additional attributes such as Storage and Enclosure credentials that are used by tests:

storageSystemHostname=10.10.10.10
storageSystemPassword=dcs
enclosureHostname=10.10.10.10
domain=LOCAL
username=administrator
enclosurePassword=dcs
file_sdk_config=src/test/resources/oneview_java_sdk_config.properties
version=V_300
storageSystemUsername=dcs
hostname=10.10.10.10
password=rainforest
enclosureUsername=dcs

Feature Requests

If you have a need that is not being met by the current implementation, please let us know (via a new issue). This feedback is crucial for us to deliver a useful product. Do not assume that we have already thought of everything, because we assure you that is not the case.

License

The OneView SDK for Java is released under version 2.0 of the Apache License.

oneview-sdk-java's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oneview-sdk-java's Issues

Deserialization error in getAllAttachmentPaths

Scenario/Intent

com.hp.ov.sdk.rest.client.storage.StorageVolumeAttachmentClient.getAllAttachmentPaths(String) returns a deserialization error.

Exception in thread "main" com.hp.ov.sdk.exceptions.SDKInternalException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

Bug was found by BDD test Scenario: Get all Storage Volume Attachment Paths (storageVolumeAttachment.feature).


Steps to Reproduce

  1. Run com.hp.ov.sdk.rest.client.storage.StorageVolumeAttachmentClientSample.getAllStorageVolumeAttachmentPaths() using a Synergy appliance V3.10.

Expected Result

Operation should be correctly executed.
Remember to also enable and test "Scenario: Get all Storage Volume Attachment Paths" in storageVolumeAttachment.feature files (for C7000 and Synergy).

Actual Result

Error returned:
[2017-08-03 16:53:27,523] INFO ObjectToJsonConverter:jsonToResource:81 - JSON successfully converted to a resource of type java.util.List<com.hp.ov.sdk.dto.storage.StorageVolumeAttachmentPath> Exception in thread "main" com.hp.ov.sdk.exceptions.SDKInternalException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ at com.hp.ov.sdk.util.ObjectToJsonConverter.jsonToResource(ObjectToJsonConverter.java:85) at com.hp.ov.sdk.adaptors.ResourceAdaptor.buildResource(ResourceAdaptor.java:37) at com.hp.ov.sdk.rest.client.BaseClient.executeRequest(BaseClient.java:86) at com.hp.ov.sdk.rest.reflect.ClientRequestHandler.handleInvocation(ClientRequestHandler.java:65) at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87) at com.sun.proxy.$Proxy6.getAllAttachmentPaths(Unknown Source) at com.hp.ov.sdk.rest.client.storage.StorageVolumeAttachmentClientSample.getAllStorageVolumeAttachmentPaths(StorageVolumeAttachmentClientSample.java:75) at com.hp.ov.sdk.rest.client.storage.StorageVolumeAttachmentClientSample.main(StorageVolumeAttachmentClientSample.java:110) Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ at com.google.gson.Gson.fromJson(Gson.java:817) at com.google.gson.Gson.fromJson(Gson.java:770) at com.google.gson.Gson.fromJson(Gson.java:719) at com.hp.ov.sdk.util.ObjectToJsonConverter.jsonToResource(ObjectToJsonConverter.java:83) ... 7 more Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60) at com.google.gson.Gson.fromJson(Gson.java:805) ... 10 more


Environment Details

  • OneView Java SDK: 3.1.1
  • OneView Appliance Version: 3.10 (synergy_3encl_demo)
  • OneView Client API Version: 300
  • Java Version: 1.7
  • Platform: Windows 10

Attachments and Screenshots

authLoginDomain should not be "Local" by default

Scenario/Intent

While establishing a connection to OneView , the login domain should not be Local by default. It should be set to an empty string. That way the default domain will be whatever is configured in OneView.

Steps to Reproduce

Set the default directory in OneView to something other than Local.
Log in using the SDK with a user associated with the above directory and do not send a login domain field.
The API should allow to log in.

Expected Result

Actual Result


Environment Details

  • OneView Java SDK:

    3.1.2
  • OneView Appliance Version:
  • OneView Client API Version:
  • Java Version:
  • Platform:

Attachments and Screenshots

SCMB authentication issue with a CA-signed certificate

Scenario/Intent

We have some authentication problems with our SCMB when we use CA-Signed client certificates. With Self-signed certificate, our script works fine.

We have followed the instructions in the User Guide found here: https://support.hpe.com/hpesc/public/docDisplay?docId=sd00001194en_us&docLocale=en_US&page=s_create-CA-cert-SCMB.html and https://support.hpe.com/hpesc/public/docDisplay?docId=sd00001194en_us&docLocale=en_US&page=s_ts-security-connect-SCMB-CA-sign-cert.html

We are using the following:

SDKConfiguration sdkConfiguration = SDKConfiguration.create()
                        .withOneViewHostname(“x.x.x.x”)
                        .withOneViewUser(<username>, <password>)
                        .withOneViewApiVersion(ApiVersion.V_500)
                        .withTrustStore(“/<directory>/TrustStore”, <truststore password>)
                        .build();
OneViewClient oneViewClient = new OneViewClient(sdkConfiguration);
MessageBusClient client = MessageBusClient.connect(sdkConfiguration, oneViewClient);

It fails in MessageBusClient.connect API call with message sun.security.validator.ValidatorException: No trusted certificate found

Our client certificate and SCMB server certificate are signed by our CA and our CA certificate is present in our host's trust store from which we run this Java login script.

What is the problem?


Environment Details

  • OneView Java SDK:
    3.2.1
  • OneView Appliance Version:
    6.30
  • OneView Client API Version:
    500

Attachments and Screenshots

Question: How much connections can be created using SDK

Hello!

Do you have any documented information regarding how much scmb connections can be created to Hp One View server using your sdk. Is that limited? Possibly I will need to create about 10-15 different connections (to get info for each blade separately)

Regards,

Dmitriy

SCMB client reconnet issue

This issue is tested using ScmbClient in Samples project and has an affect on two versions of sdk - 1.2 and 2.0.
The SCMB client starts again incorrectly after invocation of scmbClient.stopScmb():
scmbClient.scmbProcessor();
<some timeout to receive messages>
scmbClient.stopScmb();
scmbClient.scmbProcessor();
There is an AlreadyClosedExcepption on the second invocation of scmbClient.scmbProcessor();:
Exception in thread "pool-4-thread-2" com.rabbitmq.client.AlreadyClosedException: connection is already closed due to clean connection shutdown; protocol method: #method<connection.close>(reply-code=200, reply-text=OK, class-id=0, method-id=0) at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:195) at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:228) at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:214) at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118) at com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:833) at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.queueDeclare(AutorecoveringChannel.java:259) at com.hp.ov.sdk.messaging.scmb.services.ScmbProcessor.run(ScmbProcessor.java:57) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Need to add API to load active alarms only

Hello,

Trying to use sdk with 3.1.0 version. And I see that there are no any possibility to load active alarms only (we have about 10k old alartms in the system - so it took really long time to load all of them)
Is there any chance to add such useful method to the API.

image

client.getAllActive() for example

Thank you!

is this repo getting updates?

is this still being maintained?

It has not been updated in about 5 years I'm pretty sure oneview has had updates since then


Steps to Reproduce

Expected Result

Actual Result


Environment Details

  • OneView Java SDK:
  • OneView Appliance Version:
  • OneView Client API Version:
  • Java Version:
  • Platform:

Attachments and Screenshots

Unable to get all alarms using client.get() alarms call with the filter

Scenario/Intent

I'm trying to get all active alarms from Hp One View using query below:

BasicURIQuery filterByActive = new BasicURIQuery();
filterByActive.addParameter(URIQuery.FILTER, "alertState='Active'");
ResourceCollection alerts = this.client.get(filterByActive);


Steps to Reproduce

Run code above or create rest request from browser

Expected Result

All alarms from Hp One View web interfaces were received by client.get() call

Actual Result

Only couple alarms received


Environment Details

  • OneView Java SDK: 3.1.0 (the same result with 3.2.1)
  • OneView Appliance Version: 3.1.0
  • OneView Client API Version: 3.1.0
  • Java Version: 1.8
  • Platform: Windows 7 x64

Attachments and Screenshots

Web Interface (15 alarms):

hpdashboard

Detailed:

  1. Critical (not received in the alarms request)
    hpcritical

  2. Warning (received in the alarms request)
    hpwarn1

  3. Warning (not received in the alarms request)
    hpwarn2

Response from https://xx.xx.xx.xx/rest/alerts

RestAlertsResponse.txt

Main question is - why such alarms are not available in the rest response.
Are they system alarms that can be received in some any other way?
I'm able to get critical alarm above by SCMB, but customer wants to have it in the getAlarms() or any similar synchronize call.

Regards,

Dmitriy

Logout method in LoginSessionClient

Scenario/Intent

Need a logout method in LoginSessionClient. Cannot find a logout method


Steps to Reproduce

Expected Result

Actual Result


Environment Details

  • OneView Java SDK:

    3.1.2
  • OneView Appliance Version:
  • OneView Client API Version:
  • Java Version:
  • Platform:

Attachments and Screenshots

Question. KeyStore and TrustStore automatic generation.

Hello, do you have the some sort of the script that helps user to generate Store files automatically.
Which way is the best to create that one? Curl usage possibly?

curl -X POST -H "Content-Type:application/json" -d '{"userName":"{USERNAME}","password":"{PASSWORD}"}'
-k https://{HOST}/rest/login-sessions

Thank you!

Dmitriy

Getting all Storage Volumes using REST API

I have more than 10 storage volumes defined in Oneview, however, StorageVolumeCollection.getMembers() returns only 10. Don't see a way to get more than 10 using the java sdk.

Error updating Logical Switch "CRM_INCORRECT_VALUE_IN_READONLY_FIELD"

Scenario/Intent

Update logical switch fails with the following error:
"CRM_INCORRECT_VALUE_IN_READONLY_FIELD", "The expected value for field modified is 2017-08-24T12:13:59.868Z but the actual value was 2017-08-24T09:13:59.868-03."

If executed via GUI/POSTMAN, the operation is successful.

NOTE: Bug found in automation. After the issue is fixed, enable test scenario "Scenario: Update a Logical Switch" in logicalSwitch.feature.


Steps to Reproduce

Using a C7000 DCS, run com.hp.ov.sdk.rest.client.networking.LogicalSwitchClientSample.updateLogicalSwitch() and verify the error.

Expected Result

Update should be correctly executed and test scenario "Scenario: Update a Logical Switch" should be passing.

Actual Result

Following error is returned:

[2017-08-24 09:56:06,899] INFO HttpRestClient:getResponse:377 - Response Body: {"errorSource":"logical-switches","nestedErrors":[],"details":"","recommendedActions":[""],"errorCode":"CRM_INCORRECT_VALUE_IN_READONLY_FIELD","data":{},"message":"The expected value for field modified is 2017-08-24T12:13:59.868Z but the actual value was 2017-08-24T09:13:59.868-03."} Exception in thread "main" com.hp.ov.sdk.exceptions.SDKBadRequestException at com.hp.ov.sdk.rest.http.core.client.HttpRestClient.checkResponse(HttpRestClient.java:467) at com.hp.ov.sdk.rest.http.core.client.HttpRestClient.getResponse(HttpRestClient.java:378) at com.hp.ov.sdk.rest.http.core.client.HttpRestClient.sendRequest(HttpRestClient.java:249) at com.hp.ov.sdk.rest.client.BaseClient.executeRequest(BaseClient.java:123) at com.hp.ov.sdk.rest.client.BaseClient.executeMonitorableRequest(BaseClient.java:103) at com.hp.ov.sdk.rest.reflect.ClientRequestHandler.handleInvocation(ClientRequestHandler.java:61) at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87) at com.sun.proxy.$Proxy6.update(Unknown Source) at com.hp.ov.sdk.rest.client.networking.LogicalSwitchClientSample.updateLogicalSwitch(LogicalSwitchClientSample.java:91) at com.hp.ov.sdk.rest.client.networking.LogicalSwitchClientSample.main(LogicalSwitchClientSample.java:173)


Environment Details

  • OneView Java SDK: 3.1.1
  • OneView Appliance Version: 3.10 (C7000_4Encl)
  • OneView Client API Version: 300
  • Java Version: 1.7
  • Platform: Windows 10

Attachments and Screenshots

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.