Skip to content

Commit 6151d9a

Browse files
Complete operator functionality (#235)
* Make the operator work Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com> * Upgrade xbuilder version Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com> * Upgrade xbuilder version Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com> Signed-off-by: carlosthe19916 <2582866+carlosthe19916@users.noreply.github.com>
1 parent bc6997a commit 6151d9a

File tree

13 files changed

+277
-61
lines changed

13 files changed

+277
-61
lines changed

application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>io.github.project-openubl</groupId>
6060
<artifactId>quarkus-xbuilder</artifactId>
61-
<version>2.0.0.Beta2</version>
61+
<version>2.0.0-Beta4</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>io.github.project-openubl</groupId>

application/src/main/java/io/github/project/openubl/ublhub/files/health/impl/S3ReadinessCheck.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,32 @@
2727
import java.net.http.HttpClient;
2828
import java.net.http.HttpRequest;
2929
import java.net.http.HttpResponse;
30+
import java.util.Optional;
3031

3132
@ApplicationScoped
3233
@StorageProvider(StorageProvider.Type.S3)
3334
public class S3ReadinessCheck implements StorageReadinessCheck {
3435

3536
@ConfigProperty(name = "openubl.storage.s3.health.url")
36-
String s3HostHealthCheckUrl;
37+
Optional<String> s3HostHealthCheckUrl;
3738

3839
private final HttpClient client = HttpClient.newHttpClient();
3940

4041
@Override
4142
public boolean isHealthy() {
42-
try {
43-
HttpRequest request = HttpRequest.newBuilder()
44-
.uri(new URI(s3HostHealthCheckUrl))
45-
.GET()
46-
.build();
47-
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
48-
return response.statusCode() == 200;
49-
} catch (URISyntaxException | IOException | InterruptedException e) {
50-
return false;
43+
if (s3HostHealthCheckUrl.isPresent()) {
44+
try {
45+
HttpRequest request = HttpRequest.newBuilder()
46+
.uri(new URI(s3HostHealthCheckUrl.get()))
47+
.GET()
48+
.build();
49+
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
50+
return response.statusCode() == 200;
51+
} catch (URISyntaxException | IOException | InterruptedException e) {
52+
return false;
53+
}
54+
} else {
55+
return true;
5156
}
5257
}
5358
}

application/src/main/java/io/github/project/openubl/ublhub/models/TsidUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class TsidUtil {
2727

28-
@ConfigProperty(name = "ublhub.tsid.bytes")
28+
@ConfigProperty(name = "openubl.ublhub.tsid.bytes")
2929
int tsidBytes;
3030

3131
@Produces

application/src/main/java/io/github/project/openubl/ublhub/scheduler/SchedulerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@ApplicationScoped
3131
public class SchedulerManager {
3232

33-
@ConfigProperty(name = "openubl.scheduler.type")
33+
@ConfigProperty(name = "openubl.ublhub.scheduler.type")
3434
String schedulerType;
3535

3636
@Inject

application/src/main/java/io/github/project/openubl/ublhub/security/DisabledAuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@ApplicationScoped
3030
public class DisabledAuthController extends AuthorizationController {
3131

32-
@ConfigProperty(name = "ublhub.disable.authorization")
32+
@ConfigProperty(name = "openubl.ublhub.disable.authorization")
3333
boolean disableAuthorization;
3434

3535
@Override

application/src/main/java/io/github/project/openubl/ublhub/ubl/builder/idgenerator/impl/GeneratedIDGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GeneratedIDGenerator implements IDGenerator {
4242
public static final String SERIE_PROPERTY = "serie";
4343
public static final String NUMERO_PROPERTY = "numero";
4444

45-
@ConfigProperty(name = "openubl.xbuilder.timezone")
45+
@ConfigProperty(name = "openubl.ublhub.timezone")
4646
String timezone;
4747

4848
@Inject

application/src/main/resources/application.properties

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Resources
22
quarkus.native.resources.includes=schemas/*.json
33

4+
# For Key generation
5+
quarkus.security.security-providers=BC
6+
47
# Resteasy
58
quarkus.resteasy-reactive.path=/api
69

@@ -141,20 +144,19 @@ quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENS
141144
quarkus.smallrye-openapi.store-schema-directory=src/jreleaser/templates/article
142145

143146
# XBuilder
144-
openubl.scheduler.type=vertx
145-
openubl.xbuilder.timezone=America/Lima
146-
147147
quarkus.xbuilder.moneda=PEN
148148
quarkus.xbuilder.unidad-medida=NIU
149149
quarkus.xbuilder.igv-tasa=0.18
150-
quarkus.xbuilder.icb-tasa=0.2
150+
quarkus.xbuilder.icb-tasa=0.3
151151

152152
# XSender
153153
quarkus.xsender.enable-logging-feature=false
154154

155155
# Ublhub
156-
ublhub.disable.authorization=true
157-
ublhub.tsid.bytes=256
156+
openubl.ublhub.timezone=America/Lima
157+
openubl.ublhub.scheduler.type=vertx
158+
openubl.ublhub.disable.authorization=true
159+
openubl.ublhub.tsid.bytes=256
158160

159161
# Profiles
160162
%basic.ublhub.disable.authorization=false

operator/src/main/java/io/github/project/openubl/operator/Constants.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package io.github.project.openubl.operator;
1818

19+
import io.github.project.openubl.operator.cdrs.v2alpha1.UblhubSpec;
20+
1921
import java.util.Map;
2022

2123
public class Constants {
@@ -44,6 +46,7 @@ public class Constants {
4446
public static final String INGRESS_SUFFIX = "-" + UBLHUB_NAME + "-ingress";
4547
public static final String SECRET_SUFFIX = "-" + UBLHUB_NAME + "-secret";
4648
public static final String DEPLOYMENT_SUFFIX = "-" + UBLHUB_NAME + "-deployment";
49+
public static final String PVC_SUFFIX = "-" + UBLHUB_NAME + "-pvc";
4750

4851
public static final String BASIC_AUTH_SECRET_SUFFIX = "-basic-auth";
4952

@@ -56,6 +59,14 @@ public class Constants {
5659

5760

5861
public static final String CERTIFICATES_FOLDER = "/mnt/certificates";
59-
public static final String WORKSPACES_FOLDER = "/mnt/workspace";
62+
public static final String STORAGE_FOLDER = "/mnt/ublhub-storage";
6063

64+
public static final UblhubSpec.XBuilderSpec defaultXBuilderConfig = UblhubSpec.XBuilderSpec.builder()
65+
.moneda("PEN")
66+
.igvTasa("0.18")
67+
.icbTasa("0.4")
68+
.build();
69+
public static final UblhubSpec.XSenderSpec defaultXSenderConfig = UblhubSpec.XSenderSpec.builder()
70+
.enableLoggingFeature(false)
71+
.build();
6172
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.operator.cdrs.v2alpha1;
18+
19+
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
20+
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder;
21+
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
22+
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder;
23+
import io.fabric8.kubernetes.api.model.Quantity;
24+
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder;
25+
import io.github.project.openubl.operator.Constants;
26+
import io.github.project.openubl.operator.utils.CRDUtils;
27+
import io.javaoperatorsdk.operator.api.reconciler.Context;
28+
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;
29+
30+
import java.util.Map;
31+
32+
public class UblhubFileStoragePVC extends CRUDKubernetesDependentResource<PersistentVolumeClaim, Ublhub> {
33+
34+
public UblhubFileStoragePVC() {
35+
super(PersistentVolumeClaim.class);
36+
}
37+
38+
@Override
39+
public PersistentVolumeClaim desired(Ublhub cr, Context context) {
40+
return newPersistentVolumeClaim(cr, context);
41+
}
42+
43+
@SuppressWarnings("unchecked")
44+
private PersistentVolumeClaim newPersistentVolumeClaim(Ublhub cr, Context context) {
45+
final var labels = (Map<String, String>) context.managedDependentResourceContext()
46+
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);
47+
48+
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder()
49+
.withNewMetadata()
50+
.withName(getPersistentVolumeClaimName(cr))
51+
.withNamespace(cr.getMetadata().getNamespace())
52+
.withLabels(labels)
53+
.endMetadata()
54+
.withSpec(getPersistentVolumeClaimSpec(cr))
55+
.build();
56+
return pvc;
57+
}
58+
59+
private PersistentVolumeClaimSpec getPersistentVolumeClaimSpec(Ublhub cr) {
60+
return new PersistentVolumeClaimSpecBuilder()
61+
.withAccessModes("ReadWriteOnce")
62+
.withResources(new ResourceRequirementsBuilder()
63+
.addToRequests("storage", new Quantity(cr.getSpec().getStorageSpec().getFilesystemSpec().getSize()))
64+
.build()
65+
)
66+
.build();
67+
}
68+
69+
public static String getPersistentVolumeClaimName(Ublhub cr) {
70+
return cr.getMetadata().getName() + "-filesystem" + Constants.PVC_SUFFIX;
71+
}
72+
73+
public static boolean isTlsConfigured(Ublhub cr) {
74+
var tlsSecret = CRDUtils.getValueFromSubSpec(cr.getSpec().getHttpSpec(), UblhubSpec.HttpSpec::getTlsSecret);
75+
return tlsSecret.isPresent() && !tlsSecret.get().trim().isEmpty();
76+
}
77+
78+
}

operator/src/main/java/io/github/project/openubl/operator/cdrs/v2alpha1/UblhubSpec.java

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ public class UblhubSpec {
7272
@JsonPropertyDescription("In this section you can configure Oidc settings.")
7373
private OidcSpec oidcSpec;
7474

75-
@JsonProperty("sunat")
76-
@JsonPropertyDescription("In this section you can configure SUNAT settings.")
77-
private SunatSpec sunatSpec;
75+
@JsonProperty("storage")
76+
@JsonPropertyDescription("In this section you can configure the Storage.")
77+
private StorageSpec storageSpec;
78+
79+
@JsonProperty("xbuilder")
80+
@JsonPropertyDescription("XBuilder settings.")
81+
private XBuilderSpec xBuilderSpec;
82+
83+
@JsonProperty("xsender")
84+
@JsonPropertyDescription("XSender settings.")
85+
private XSenderSpec xSenderSpec;
7886

7987
@Data
8088
@Builder
@@ -152,12 +160,78 @@ public static class OidcSpec {
152160
@Builder
153161
@AllArgsConstructor
154162
@NoArgsConstructor
155-
public static class SunatSpec {
156-
@JsonPropertyDescription("Padron Reducido Url.")
157-
private String padronReducidoUrl;
163+
public static class StorageSpec {
164+
public enum Type {
165+
filesystem,
166+
s3
167+
}
168+
169+
@JsonPropertyDescription("Typo of chosen storage.")
170+
private Type type;
171+
172+
@JsonProperty("filesystem")
173+
@JsonPropertyDescription("Filesystem settings.")
174+
private StorageFilesystemSpec filesystemSpec;
175+
176+
@JsonProperty("s3")
177+
@JsonPropertyDescription("Filesystem settings.")
178+
private StorageS3Spec s3Spec;
179+
}
158180

159-
@JsonPropertyDescription("Cron for downloading the Padron Reducido.")
160-
private String padronReducidoCron;
181+
@Data
182+
@Builder
183+
@AllArgsConstructor
184+
@NoArgsConstructor
185+
public static class StorageFilesystemSpec {
186+
@JsonPropertyDescription("Size of the PVC to create.")
187+
private String size;
161188
}
162189

190+
@Data
191+
@Builder
192+
@AllArgsConstructor
193+
@NoArgsConstructor
194+
public static class StorageS3Spec {
195+
@JsonPropertyDescription("Only if you are using Minio, otherwise leave it empty")
196+
private String host;
197+
198+
@JsonPropertyDescription("Only if you are using Minio, otherwise leave it empty")
199+
private String healthUrl;
200+
201+
@JsonPropertyDescription("Region")
202+
private String region;
203+
204+
@JsonPropertyDescription("Bucket")
205+
private String bucket;
206+
207+
@JsonPropertyDescription("Access key id")
208+
private String accessKeyId;
209+
210+
@JsonPropertyDescription("Secret access key")
211+
private String secretAccessKey;
212+
}
213+
214+
@Data
215+
@Builder
216+
@AllArgsConstructor
217+
@NoArgsConstructor
218+
public static class XBuilderSpec {
219+
@JsonPropertyDescription("Default currency")
220+
private String moneda = "PEN";
221+
222+
@JsonPropertyDescription("Default IGV")
223+
private String igvTasa;
224+
225+
@JsonPropertyDescription("Default ICB")
226+
private String icbTasa;
227+
}
228+
229+
@Data
230+
@Builder
231+
@AllArgsConstructor
232+
@NoArgsConstructor
233+
public static class XSenderSpec {
234+
@JsonPropertyDescription("Enable logging feature")
235+
private Boolean enableLoggingFeature = false;
236+
}
163237
}

0 commit comments

Comments
 (0)