Monday, January 30, 2023

rebuild terraform deprecated packages like terraform-provider-template or terraform-provider-local

 on a m1 mac os laptop you might run into deprecated terraform packages : 

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/template: no available releases match the given constraints >=
│ 2.1.0
╵

ERRO[0011] Terraform invocation failed in /Users/]
ERRO[0011] 1 error occurred:
	* exit status 1

To solve, just rebuild it locally on your mac like so for the missing provider: 

cd /tmp
git clone https://github.com/hashicorp/terraform-provider-template.git
cd terraform-provider-template
git checkout v2.1.0
go build 
mkdir -p ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.1.0/darwin_arm64
mv terraform-provider-template ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.1.0/darwin_arm64/
chmod u+x ${HOME}/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.1.0/darwin_arm64/terraform-provider-template

Friday, April 19, 2019

migrating big query TABLE_DATE_RANGE equivalent in standard sql

To query a big query table with date time function called  TABLE_DATE_RANGE into standard  sql
like for  example if you run this  :
FROM (TABLE_DATE_RANGE([hd-cust-account-prod:exported_LB_logs_v2.requests_],DATE_ADD(CURRENT_TIMESTAMP(), -10, 'MINUTE'),CURRENT_TIMESTAMP()))
you will get the error "Table-valued function not found: TABLE_DATE_RANGE" 



To fix this you  can use the following in standard sql to get the last x minutes in big query using a combination of _TABLE_SUFFIX and TIMESTAMP_SUB like so:

SELECT *
FROM `hd-gcpproject-prod.someapptable_output_log_*`
WHERE timestamp BETWEEN
  TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 MINUTE) AND
  CURRENT_TIMESTAMP() and PARSE_DATE('%Y%m%d', _TABLE_SUFFIX) BETWEEN
  DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) AND
  CURRENT_DATE();

Wednesday, December 12, 2018

Mutual SSL Setup

kubectl x509: certificate signed by unknown authority

kubectl issues



$ kubectl run hello-app --image gcr.io/hellow-app/hello-ap:v1 --port 8080

error: failed to discover supported resources: Get https://35.227.95.71/apis/extensions/v1beta1: x509: certificate signed by unknown authority


rather than --insecure-skip-tls-verify=true,
then recreate the cluster config:

gcloud container clusters get-credentials hello-app-cluster --zone us-east1-b --project yourgcpproject

Monday, August 31, 2015

artifactory error on deploy

I occasionally got these errors in artifactory.log when i tried to deploy an artifact manually after configuring it.

2015-08-31 11:24:15,138 [http-nio-8081-exec-4] [ERROR] (o.a.r.c.e.GlobalExceptionMapper:46) - null
java.lang.NullPointerException: null
        at org.artifactory.repo.virtual.VirtualRepo.remoteRepositoryByRemoteOrCacheKey(VirtualRepo.java:277) ~[artifactory-core-4.0.1.jar:na]
        at org.artifactory.repo.virtual.VirtualRepo.localOrCachedRepositoryByKey(VirtualRepo.java:252) ~[artifactory-core-4.0.1.jar:na]
        at org.artifactory.repo.service.RepositoryServiceImpl.localOrCachedRepoDescriptorByKey(RepositoryServiceImpl.java:1425) ~[artifactory-core-4.0.1.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]

        at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]

I solved  this by making sure that the  disk in  storage.properties file is correct
and making sure that the user has permission to allow it to deploy to the repo for example libs-release-local.



Thursday, September 11, 2014

Apache CXF and JAXB to convert Date object to json custom formatted string

Sometimes your api requires that you print a custom formatted ui friendly date rather than a long timestamp. Following shows you how to create a adapter so your json model returned from the api contains custom formatted date for example.

1) first Maven you will need the following at least:
<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
         <version>1.9.13</version>
         </dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-xc</artifactId>
            <version>1.9.13</version>
  </dependency>  
2) assuming you apache CXF config should look like so to add the JacksonJaxbJsonProvider, like so in your spring config file:

    <jaxrs:server id="someservice" address="/">
       <jaxrs:serviceBeans>
           <bean class="com.company.ListAPI" />          
       </jaxrs:serviceBeans>  
        <jaxrs:extensionMappings>
        <entry key="json" value="application/json"></entry>
           <entry key="xml" value="application/xml"></entry>
        </jaxrs:extensionMappings>
        <jaxrs:features>
             <cxf:logging/>
        </jaxrs:features>
        <jaxrs:providers>
    <ref bean="jsonProvider"/>
</jaxrs:providers>
        </jaxrs:server>
      <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>


3) now annotate your model that you pass back in your api like so:

public class SomeModel {
       @XmlJavaTypeAdapter(StartDateAdapter.class)
protected Date startDate=new Date();
//other properties//getters/setters...
}

4) implement the adapter that converts between string and date:

    public class StartDateAdapter extends XmlAdapter<String, Date>{

@Override
public Date unmarshal(String value) throws Exception {
DateFormat date = new SimpleDateFormat("dd-MM-yyyy HH:mm");
       if (value == null || value.length() == 0) {
           return null;
       }
       Date d = null;

       try {
           d = date.parse(value);
       } catch (Exception e) {
           e.printStackTrace();
           return null;
       }
       return d;
}

@Override
public String marshal(Date value) throws Exception {
if (value == null) {
           return null;
       }
       DateFormat date = new SimpleDateFormat("dd-MM-yyyy HH:mm");
       return date.format(value.getTime());
}

}


Thats it!
now whenever you get the json or send the json in your API, like so in apache cxf endpoint, jaxb will will use your adapter to make your date look meanigful.

 @POST
@Path(value = "/start")
@Consumes(MediaType.APPLICATION_JSON)
public Response  startDeploys(
@RequestBody(required = true) SomeModel userModel) {
               Date userInputDate =usermodel.getStartDate();
                return Response.ok("Date you entered in the body of the post looks good..thanks").build();
       }


  @GET
@Path(value = "/list")
public Response  startDeploys(
@RequestBody(required = true) SomeModel userModel) {
             return Response.ok( new SomeModel () ).build();
       }






Monday, August 11, 2014

incompatible JPA spec

Sometimes you can get an error like so:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/sprin
g/spring-orm.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMod
e()Ljavax/persistence/ValidationMode;


It could also mean that the dependency you are including may be dependent on an incompatible dependency with your project.
for example..
you can do <exclusions> tag to not package the offending dependency in your war by doing something like this:

<dependency>
   <groupId>com.ibm.websphere</groupId>
   <artifactId>wxsutils</artifactId>
   <version>2.5.4-SNAPSHOT</version>
           <exclusions>
                 <exclusion>
                   <groupId>org.apache.geronimo.specs</groupId>
                   <artifactId>geronimo-jpa_3.0_spec</artifactId>
                </exclusion>
           </exclusions>
</dependency>