Skip to content

Commit

Permalink
[TH2-5226] Enabled style check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Sep 20, 2024
1 parent b409e5b commit a77dd93
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 134 deletions.
24 changes: 13 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'application'
// id 'checkstyle'
// alias(libs.plugins.detekt)
id 'checkstyle'
alias(libs.plugins.detekt)
alias(libs.plugins.kotlin)
alias(libs.plugins.th2.component)
alias(libs.plugins.download)
Expand All @@ -18,15 +18,15 @@ repositories {
mavenCentral()
}

//checkstyle {
// toolVersion = "10.12.4"
//}
checkstyle {
toolVersion = "10.12.4"
}

//detekt {
// buildUponDefaultConfig = true
// autoCorrect = true
// config.setFrom("$rootDir/config/detekt/detekt.yml")
//}
detekt {
buildUponDefaultConfig = true
autoCorrect = true
config.setFrom("$rootDir/config/detekt/detekt.yml")
}

dependencies {
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"
Expand Down Expand Up @@ -71,7 +71,7 @@ dependencies {
testImplementation libs.awaitility
testImplementation libs.strikt.core

// detektPlugins libs.detekt.formatting
detektPlugins libs.detekt.formatting
}

wrapper {
Expand All @@ -92,6 +92,8 @@ tasks.register("downloadCRDs", Download) {
dest layout.buildDirectory.dir('resources/test/crds').get()
}

checkstyleTest.dependsOn("downloadCRDs")

test {
dependsOn("downloadCRDs")
useJUnitPlatform {
Expand Down
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ complexity:
active: true
functionThreshold: 6
constructorThreshold: 15
ignoreDefaultParameters: false
ignoreDefaultParameters: true
ignoreDataClasses: false
ignoreAnnotatedParameter: []
MethodOverloading:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ public class Th2CrdController implements AutoCloseable {
private static final Logger LOGGER = LoggerFactory.getLogger(Th2CrdController.class);

private final PrometheusServer prometheusServer;

private final KubernetesClient kubClient;

private final DefaultWatchManager watchManager;

private final RabbitMQContext rabbitMQContext;

private final ContinuousTaskWorker continuousTaskWorker;

public Th2CrdController() throws IOException, URISyntaxException {
Expand All @@ -68,7 +72,8 @@ public Th2CrdController() throws IOException, URISyntaxException {

OperatorMetrics.resetCacheErrors();
RabbitMQUtils.deleteRabbitMQRubbish(kubClient, rabbitMQContext);
rabbitMQContext.declareTopicExchange(); // FIXME: topic exchange should be removed when all namespaces are removed / disabled
// TODO: topic exchange should be removed when all namespaces are removed / disabled
rabbitMQContext.declareTopicExchange();

watchManager.addTarget(MstoreHelmTh2Op::new);
watchManager.addTarget(EstoreHelmTh2Op::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

public class PrometheusServer implements AutoCloseable {
private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusServer.class);

@Nullable
private final HTTPServer server;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ protected void processEvent(Action action, CR resource) throws IOException {
.withName(helmReleaseName);
HelmRelease helmRelease = helmReleaseResource.get();
if (helmRelease == null) {
LOGGER.info("Resource \"{}\" hasn't been deleted because it already doesn't exist", annotationFor(namespace, helmReleaseName, HelmRelease.class.getSimpleName()));
LOGGER.info("Resource \"{}\" hasn't been deleted because it already doesn't exist",
annotationFor(namespace, helmReleaseName, HelmRelease.class.getSimpleName()));
} else {
String helmReleaseLabel = annotationFor(helmRelease);
helmReleaseResource.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public abstract class HelmReleaseTh2Op<CR extends Th2CustomResource> extends Abs
helmReleaseClient;

protected final DeclareQueueResolver declareQueueResolver;

protected final BindQueueLinkResolver bindQueueLinkResolver;

public HelmReleaseTh2Op(KubernetesClient kubClient, RabbitMQContext rabbitMQContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public static ConfigMapEventHandler newInstance(SharedInformerFactory sharedInfo
return res;
}

private ConfigMapEventHandler(KubernetesClient kubClient, RabbitMQContext rabbitMQContext, DefaultWatchManager watchManager) {
private ConfigMapEventHandler(KubernetesClient kubClient,
RabbitMQContext rabbitMQContext,
DefaultWatchManager watchManager) {
this.kubClient = kubClient;
this.rabbitMQContext = rabbitMQContext;
this.watchManager = watchManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ private EventHandlerContext registerInformers(SharedInformerFactory sharedInform

EventHandlerContext context = new EventHandlerContext();

context.addHandler(NamespaceEventHandler.newInstance(sharedInformerFactory, rabbitMQContext, eventDispatcher.getEventQueue()));
context.addHandler(NamespaceEventHandler.newInstance(sharedInformerFactory,
rabbitMQContext,
eventDispatcher.getEventQueue()));
context.addHandler(Th2DictionaryEventHandler.newInstance(sharedInformerFactory, kubClient,
eventDispatcher.getEventQueue()));
context.addHandler(ConfigMapEventHandler.newInstance(sharedInformerFactory, kubClient, rabbitMQContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ public final class RabbitMQContext implements AutoCloseable {
private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQContext.class);

private static final int RETRY_DELAY = 120;

public static final String TOPIC = BuiltinExchangeType.TOPIC.getType();

public static final String DIRECT = BuiltinExchangeType.DIRECT.getType();

private final RabbitMQManagementConfig managementConfig;

private final ChannelContext channelContext;

private final Client rmqClient;
Expand Down Expand Up @@ -322,15 +326,22 @@ public QueueInfo getQueue(String queueName) {
}
}

public static Client createClient(String host, int port, String username, String password) throws MalformedURLException, URISyntaxException {
public static Client createClient(
String host,
int port,
String username,
String password
) throws MalformedURLException, URISyntaxException {
return new Client(new ClientParameters()
.url(format("http://%s:%s/api", host, port))
.username(username)
.password(password)
);
}

private static Client createClient(RabbitMQManagementConfig rabbitMQMngConfig) throws MalformedURLException, URISyntaxException {
private static Client createClient(
RabbitMQManagementConfig rabbitMQMngConfig
) throws MalformedURLException, URISyntaxException {
return createClient(rabbitMQMngConfig.getHost(),
rabbitMQMngConfig.getManagementPort(),
rabbitMQMngConfig.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ class BindQueueLinkResolver(
}
if (attributes.contains(PinAttribute.parsed.name)) {
K_LOGGER.warn {
"Detected a pin: $resourceLabel:$pinName with incorrect store configuration. attribute 'parsed' not allowed"
"Detected a pin: $resourceLabel:$pinName with incorrect store configuration. " +
"attribute 'parsed' not allowed"
}
return false
}
if (!attributes.contains(PinAttribute.raw.name)) {
K_LOGGER.warn {
"Detected a pin: $resourceLabel:$pinName with incorrect store configuration. attribute 'raw' is missing"
"Detected a pin: $resourceLabel:$pinName with incorrect store configuration. " +
"attribute 'raw' is missing"
}
return false
}
Expand All @@ -112,7 +114,7 @@ class BindQueueLinkResolver(
val queueName = queue.queueName.toString()
val currentQueue = rabbitMQContext.getQueue(queueName)
if (currentQueue == null) {
K_LOGGER.info {"Queue '$queueName' does not yet exist. skipping binding" }
K_LOGGER.info { "Queue '$queueName' does not yet exist. skipping binding" }
return
}
channel.queueBind(queue.queueName.toString(), queue.exchange, queue.routingKey.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ fun close(closeable: AutoCloseable, name: String) {
} catch (e: Exception) {
K_LOGGER.error(e) { "$name close failure" }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ class DeleteRubbishOnStartTest {
Th2CrdController().use {
assertAll(
queues.map { queue ->
{ rabbitMQClient.assertNoQueue(queue, RABBIT_MQ_V_HOST) }
{
rabbitMQClient.assertNoQueue(queue, RABBIT_MQ_V_HOST)
}
} + exchanges.map { exchange ->
{ rabbitMQClient.assertNoExchange(exchange, RABBIT_MQ_V_HOST) }
{
rabbitMQClient.assertNoExchange(exchange, RABBIT_MQ_V_HOST)
}
} + listOf(
{ rabbitMQClient.assertNoQueues("link\\[.*\\]", RABBIT_MQ_V_HOST) },
{ rabbitMQClient.assertNoExchanges("${TH2_PREFIX}.*", RABBIT_MQ_V_HOST) }
Expand Down Expand Up @@ -162,16 +166,27 @@ class DeleteRubbishOnStartTest {
channel.confirmSelect()
/** queue of not existed component */
val queue01 = channel.createQueue(namespaceB, "rubbish-component", PIN_NAME).assertQueue()

/** queue of not exited pin */
val queue02 = channel.createQueue(namespaceB, component, "rubbish-pin").assertQueue()

/** mstore queue of not existed namespace */
val queue03 = channel.createQueue(namespaceC, MESSAGE_STORAGE_BOX_ALIAS, MESSAGE_STORAGE_PIN_ALIAS).assertQueue()
val queue03 = channel.createQueue(
namespaceC,
MESSAGE_STORAGE_BOX_ALIAS,
MESSAGE_STORAGE_PIN_ALIAS
).assertQueue()

/** mstore queue of existed namespace */
val queue11 = channel.createQueue(namespaceB, MESSAGE_STORAGE_BOX_ALIAS, MESSAGE_STORAGE_PIN_ALIAS).assertQueue()
val queue11 = channel.createQueue(
namespaceB,
MESSAGE_STORAGE_BOX_ALIAS,
MESSAGE_STORAGE_PIN_ALIAS
).assertQueue()
.also {
channel.basicPublish("", it.queue, null, "test-content".toByteArray())
}

/** queue of exited component and pin */
val queue12 = channel.createQueue(namespaceB, component, PIN_NAME).assertQueue()
.also {
Expand Down Expand Up @@ -209,7 +224,7 @@ class DeleteRubbishOnStartTest {

rabbitMQClient.assertQueue(queue11.queue, RABBIT_MQ_QUEUE_CLASSIC_TYPE, RABBIT_MQ_V_HOST)
rabbitMQClient.awaitQueueSize(queue11.queue, RABBIT_MQ_V_HOST, 1)
rabbitMQClient.assertQueue(queue12.queue, RABBIT_MQ_QUEUE_CLASSIC_TYPE, RABBIT_MQ_V_HOST)
rabbitMQClient.assertQueue(queue12.queue, RABBIT_MQ_QUEUE_CLASSIC_TYPE, RABBIT_MQ_V_HOST)
rabbitMQClient.awaitQueueSize(queue12.queue, RABBIT_MQ_V_HOST, 1)

rabbitMQClient.assertNoExchange(exchangeC, RABBIT_MQ_V_HOST)
Expand All @@ -223,7 +238,7 @@ class DeleteRubbishOnStartTest {
kubeClient.createRabbitMQAppConfigCfgMap(
namespace,
gitHash,
createRabbitMQConfig(rabbitMQContainer, RABBIT_MQ_V_HOST, toExchangeName(namespace), namespace)
createRabbitMQConfig(rabbitMQContainer, RABBIT_MQ_V_HOST, toExchangeName(namespace), namespace)
)

kubeClient.createBookConfigCfgMap(namespace, gitHash, TH2_BOOK)
Expand All @@ -248,4 +263,4 @@ class DeleteRubbishOnStartTest {

private const val PIN_NAME = "test-pin"
}
}
}
Loading

0 comments on commit a77dd93

Please sign in to comment.