Can't create instance from java sdk - oracle-cloud-infrastructure

I am trying to create an OCI instance with the Java SDK. I am getting an error in routeRules.
When I commented the following line, I was able to create an instance. But in that machines route is not enabled.
addInternetGatewayToRouteTable(vcnClient, compartmentId, vcn.getDefaultRouteTableId(), internetGateway);
https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/CreateInstanceExample.java
Exception in thread "main" com.oracle.bmc.model.BmcException: (400, InvalidParameter, false) routeRules[0].networkEntityId may not be null (opc-request-id: 6BC8A182852240F8AFFD1EB279CFF901/AD5BF82603D64DA298976FCFE83871F6/9398B04078B0435A8FA68FEA7307CC99)
at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:120)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:86)
at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:82)
at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter$1.apply(UpdateRouteTableConverter.java:70)
at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter$1.apply(UpdateRouteTableConverter.java:55)
at com.oracle.bmc.core.VirtualNetworkClient.updateRouteTable(VirtualNetworkClient.java:3325)
at CreateInstanceExample.addInternetGatewayToRouteTable(CreateInstanceExample.java:295)
at CreateInstanceExample.main(CreateInstanceExample.java:146)

There is a bug in the code, you can replace destination in the addInternetGatewayToRouteTable(..) method
RouteRule internetAccessRoute =
RouteRule.builder()
.cidrBlock("0.0.0.0/0")
.destination(internetGateway.getId())
.build();
in line 295 with networkEntityId:
RouteRule internetAccessRoute =
RouteRule.builder()
.cidrBlock("0.0.0.0/0")
.networkEntityId(internetGateway.getId())
.build();
You can see from the REST APIs here which parameters are required to create a route rule in a route table.
The example seems to be based on a deprecated version of calling the RouteRule builder.

Related

Apache camel equivalent for spring #Transactional(readonly=true)

I am trying to use Java Streams with JPA in Apache Camel Route with MySQL. I have seen few resources and they have mentioned that we need to have the below 3 properties for Streams to work properly with MySQL.
1. Forward-only resultset
2. Read-only statement
3. Fetch-size set to Integer.MIN_VALUE
I have tried setting the 2nd and 3rd property in the JPA Repository using QueryHint.
#QueryHints(value = {
#QueryHint(name = HINT_FETCH_SIZE, value = "" + Integer.MIN_VALUE),
#QueryHint(name = HINT_READONLY, value = "true")
})
Looks like Fetch-size is working, but 2nd property is not working, as I am still facing the below error:
Caused by: java.sql.SQLException: Streaming result set com.mysql.jdbc.RowDataDynamic#54b12700 is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.
I have made the route Transactional using transacted() which is equivalent to spring #Transactional. But not sure what is the equivalent for #Transactional(readonly=true). Any leads?
from("direct:" + ROUTE_ID)
.routeId(ROUTE_ID)
.log("Start the processing")
.transacted()
.bean(Processor.class)
.to("log:ProcessName?showAll=true");
I have referred this blog as reference.

How to get all ip attached to compute using python oci

I want to use python oci package to get information about environment.
how to list all IPs addresses (both public or private) attached to compute node?
list_instances() does not provide this part of compute details unfortunately.
thanks.
As shared by #Char above, this oci-python-sdk example should help you here.
You can find a list of all supported services by SDK for Python here - https://docs.cloud.oracle.com/en-us/iaas/Content/API/SDKDocs/pythonsdk.htm
Additionally, full documentation for OCI Python SDK can be found here - https://docs.cloud.oracle.com/en-us/iaas/tools/python/2.21.5/
Please use this code. Basically you have to lookup VNIC Attachment object and filter VNIC_ID based on InstanceId. VNIC_ID can be used for looking up IP Addresses subsequently.
I have used data[0] to indicate the first attachment. You could use a loop to go through all attachments and print the IP.
compute_client = oci.core.ComputeClient(config={}, signer=signer)
network_client = oci.core.VirtualNetworkClient(
config={}, signer=signer)
vnic_id = compute_client.list_vnic_attachments(
cd_compartment_id, instance_id=instanceId).data[0].vnic_id
private_ip = network_client.get_vnic(vnic_id).data.private_ip
Assuming that you have the display name of an OCI compute instance and you need its private and public IP addresses, provided that you already created an API key in your profile and that you configured your ~/.oci/config with valid pem private key downloaded when creating the API Key, the following Python code can help:
import oci
display_name = "your display name"
config = oci.config.from_file()
identity = oci.identity.IdentityClient(config)
user = identity.get_user(config["user"]).data
instances = oci.core.ComputeClient(config).list_instances(
compartment_id=user.compartment_id).data
instance_id = {i.display_name: i.id for i in instances}[display_name]
compute_client = oci.core.ComputeClient(config)
vnic_data = compute_client.list_vnic_attachments(
compartment_id=user.compartment_id, instance_id=instance_id).data
network_client = oci.core.VirtualNetworkClient(config)
vnic_list = [network_client.get_vnic(vnic_attachment.vnic_id).data
for vnic_attachment in vnic_data]
public_ip = {i.display_name: i.public_ip for i in vnic_list}[display_name]
private_ip = {i.display_name: i.private_ip for i in vnic_list}[display_name]
print(public_ip, private_ip)
This implies:
pip3 install oci oci-cli

ImageId not found in Google Compute Engine using Jclouds

I'm creating instance on the Google Compute Engine with jclouds, using the command:
Template template = context.getComputeService().templateBuilder().imageId("debian-7-wheezy-v20150710").build();
Set<? extends NodeMetadata> listNode = context.getComputeService().createNodesInGroup("teste", 1, template);
But is the error below:
2015-08-16 07:27:04 INFO compute:64 - Image debian-7-wheezy-v20150710 not found in the image cache. Trying to get it from the provider...
Exception in thread "main" java.util.NoSuchElementException: imageId(debian-7-wheezy-v20150710) not found
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.throwNoSuchElementExceptionAfterLoggingImageIds(TemplateBuilderImpl.java:764)
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.findImageWithId(TemplateBuilderImpl.java:745)
at org.jclouds.compute.domain.internal.TemplateBuilderImpl.build(TemplateBuilderImpl.java:688)
at br.com.clouddeploy.main.TestGoogle.main(TestGoogle.java:47)
Any suggestion?
If you are using imageId() you probably need to use the full path to the image. Here's how to find it:
% gcloud compute images list --uri | grep debian-7
shows:
https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/backports-debian-7-wheezy-v20150710
https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20150710
So you can use either of these. The one that starts with backports has newer versions of packages, but is still based on Debian 7 Wheezy.
Alternatively, it looks like jclouds has the ability to do this URL creation on its own, but instead of using imageId(), you should use (see GitHub code example):
ComputeService compute = initComputeService(account, credentials);
[...]
TemplateBuilder templateBuilder = compute.templateBuilder();
templateBuilder.fromImage(compute
.getImage("debian-7-wheezy-v20140408"));

Jasper string functions method undefined error

Using Jasper Reports 5.6.1. Added some text functions to a previously working text field jrxml (just want to truncate if longer than 75 chars). Works in iReport Studio, but not in Java.
<textFieldExpression><![CDATA[IF(LEN($F{AccountName})<75,$F{AccountName},LEFT($F{AccountName},75)+"...")]]></textFieldExpression>
Error message:
Error occured while trying to fetch the HTML Output from the Jasper Service (Errors were encountered when compiling report expressions class file:
1. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
2. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
3. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getOldValue()))<75,((java.lang.String)field_AccountName.getOldValue()),LEFT(((java.lang.String)field_AccountName.getOldValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
4. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getOldValue()))<75,((java.lang.String)field_AccountName.getOldValue()),LEFT(((java.lang.String)field_AccountName.getOldValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
5. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
6. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
6 errors
)
I checked packages in jasperreports-5.6.1.jar file, includes functions package. Exhaustive web search turned up nothing. What could it be?
I have a similar error message. Where you able to resolve this? Works fine in Jaspersoft Studio 6.0.1, but throws this when compiling w/ Java:
The method IF(boolean, BigDecimal, BigDecimal) is undefined for the type Blank_A4_1_1423164610392_674232
Update: I was able to solve this by including the functions jar on my classpath. See that if that works for you. See jasperreports-functions-5.6.1.jar at http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%205.6.1/
When using GlassFish, verify that you have all jasper libraries on your production server. They should be under glassfish/domains/domain1/lib/ext. If the jars are not there (or some of them, such as the fonts or some other not non-requisite lib) you might experience the behavior you are describing.

Zend: Accessing model from Bootstrap raises an exception

This is the code I have in Bootstrap:
public function _initRegistry()
{
$systemConfigModel = new Application_Model_DbTable_SystemConfig();
Zend_Registry::set('config', $systemConfigModel->getSystemConfig());
}
And this an exception I am getting:
( ! ) Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Application_Model_DbTable_SystemConfig' in /usr/share/php5/Zend/Db/Table/Abstract.php on line 755
( ! ) Zend_Db_Table_Exception: No adapter found for Application_Model_DbTable_SystemConfig in /usr/share/php5/Zend/Db/Table/Abstract.php on line 755
It works just fine if I call it within my BaseController. It just looks like the PDO adapter that I specify in application.ini has not been initialized at the time Bootstrap is executed (strange?). What should I do to make the code work in Bootstrap? Is it necessary to create and set an adapter with Zend_Db_Table::setDefaultAdapter();?
I am asking because if the code is not in Bootstrap, it needs to be duplicated in two different places and it also kind of looks like it belongs to Bootstrap.
You are correct, during bootstrap, the Zend Application resource for your database has not yet been initialized.
Try changing your bootstrap method as follows so you explicitly bootstrap the db resource.
public function _initRegistry()
{
$this->bootstrap('db'); // Bootstrap the db resource from configuration
$db = $this->getResource('db'); // get the db object here, if necessary
// now that you have initialized the db resource, you can use your dbtable object
$systemConfigModel = new Application_Model_DbTable_SystemConfig();
Zend_Registry::set('config', $systemConfigModel->getSystemConfig());
}