How to pull correct mysql from testcontainer using Quarkus - mysql

I using testcontainer and macbook m1. When i start testContainer it thow me error:
Could not pull image: no matching manifest for linux/arm64/v8 in the manifest list entries
I can't understand why because when i using postgres it ok.
Here is my config. Please help
open class MySqlResourceTest : QuarkusTestResourceLifecycleManager {
private val DATABASE: SpecifiedMySQLContainer = SpecifiedMySQLContainer("mysql:5.7.8").apply {
withDatabaseName("test")
withUsername("abc")
withPassword("123456")
withExposedPorts(3317)
}
override fun start(): MutableMap<String, String> {
DATABASE.start()
DATABASE.setCommand()
return Collections.singletonMap("quarkus.datasource.url", DATABASE.jdbcUrl)
}
override fun stop() {
DATABASE.stop()
}
}

Common testcontainer for MySql is org.testcontainers.containers.MySQLContainer. You're using a SpecifiedMySQLContainer in your code snippet, which may cause the issue.

Related

PhpStorm false inspection error by using self type hint

the inspector in PhpStorm gives me an error even though the code is valid
interface PhoneInterface
{
public function add(): self;
}
trait PhoneTrait
{
public function add(): self
{
return $this;
}
}
class A implements PhoneInterface
{
use PhoneTrait;
}
var_dump(new A());
I get the error:
"Declaration of 'PhoneTrait->add()' must be compatible with 'PhoneInterface->add()'"
But since PHP 7.4 this is valid. In the "Settings -> PHP level" I tried 7.4 and 8.0 but both gives me an error.
The error goes away if I remove the :self typehint.
The same code works here https://3v4l.org/SJCf2 and on my Server.
It's a corner case that hasn't been fixed along with the general case.

How do you hide parameters in custom build steps in Kotlin for TeamCity?

I'm trying to setup TeamCity, using config as code with Kotlin. I'm writing wrappers for buildsteps so I can hide the default exposed configuration and only expose parameters that matter. This would allow me to prevent users of the class from changing values that would cause build errors.
I want this:
steps {
step {
name = "Restore NuGet Packages"
type = "jb.nuget.installer"
param("nuget.path", "%teamcity.tool.NuGet.CommandLine.3.3.0%")
param("nuget.updatePackages.mode", "sln")
param("nuget.use.restore", "restore")
param("sln.path", "path_to_solution") //parameter here
param("toolPathSelector", "%teamcity.tool.NuGet.CommandLine.3.3.0%")
}
...to be this:
MyBuildSteps.buildstep1("path_to_solution")
Here's the function signature for step:
public final class BuildSteps {
public final fun step(base: BuildStep?, init: BuildStep.() -> Unit ): Unit { /* compiled code */ }
}
This is what I tried:
class MyBuildSteps {
fun restoreNugetPackages(slnPath: String): kotlin.Unit {
var step: BuildStep = BuildStep {
name = "Restore NuGet Packages"
type = "jb.nuget.installer"
}
var stepParams: List = Parametrized {
param("build-file-path", slnPath)
param("msbuild_version", "14.0")
param("octopus_octopack_package_version", "1.0.0.%build.number%")
param("octopus_run_octopack", "true")
param("run-platform", "x86")
param("toolsVersion", "14.0")
param("vs.version", "vs2015")
}
return {
step.name
step.type
stepParams
} //how do I return this?
}
}
Any advice would be much appreciated!
I assume you want to encapsulate step {...} into a function buildstep1 with a parameter slnPath.
Use this function signature and copy-paste the step {...} part right inside. Add any parameters you see fit:
fun BuildSteps.buildstep1(slnPath: String) {
step {
name = "Restore NuGet Packages"
type = "jb.nuget.installer"
param("nuget.path", "%teamcity.tool.NuGet.CommandLine.3.3.0%")
param("nuget.updatePackages.mode", "sln")
param("nuget.use.restore", "restore")
param("sln.path", slnPath) // your parameter here
param("toolPathSelector", "%teamcity.tool.NuGet.CommandLine.3.3.0%")
}
}
That's all! Use it instead of the step {...} construct:
steps {
buildstep1("path_to_solution")
}
This function may be declared anywhere in the configuration file (I usually place those at the bottom) or in a separate .kts file and imported (theoretically).

Create database play java evolutions

I am using play java 2.5.
I have created a database with following java code.
public OnStartup() throws SQLException {
//demo create database with java code
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=12345678");
Statement s = con.createStatement();
int Result = s.executeUpdate("CREATE DATABASE recruit3");
}
Module:
public class OnStartupModule extends AbstractModule {
#Override
public void configure() {
bind(OnStartup.class).asEagerSingleton();
}
}
application.conf:
play.modules {
enabled += "be.objectify.deadbolt.java.DeadboltModule"
enabled += modules.CustomDeadboltHook
enabled += modules.OnStartupModule
}
default.driver=com.mysql.jdbc.Driver
default.url="jdbc:mysql://localhost:3306/recruit3"
default.username=root
default.password="12345678"
My question is, why running the web-app creating
error Cannot connect to database [default]
How to fix that, if I don't want to create the database with mysql workbench.
Any suggestion or cannot do this, please tell me.
Thanks for advance.
As well as moving your database keys to the db.default namespace, you should be injecting Database into OnStartup to access the database configured with those properties.
First, add Play's JDBC support to build.sbt.
libraryDependencies += javaJdbc
If you're already running activator, make sure you use the reload command to pick up the changes to the build.
Update your application.conf to place the database configuration into the correct namespace.
db {
default {
driver=com.mysql.jdbc.Driver
url="jdbc:mysql://localhost:3306/recruit3"
username=root
password="12345678"
}
}
Finally, update OnStartup to receive a Database object that will be injected by Play.
import javax.inject.Inject;
import play.db.Database;
public class OnStartup {
#Inject
public OnStartup(final Database db) throws SQLException {
db.withConnection((Connection conn) -> {
final Statement s = con.createStatement();
return s.executeUpdate("CREATE DATABASE recruit3");
});
}
}
This allows you to configure the database one time, in application.conf, instead of hard-coding DB configuration into a class.
You can find more information here.
Your database keys start with default instead of db.default. The correct syntax is something like this:
db {
default {
driver=com.mysql.jdbc.Driver
url="jdbc:mysql://localhost:3306/recruit3"
username=root
password="12345678"
}
}
You already made your class as eager singleton, so it should work

JHipster Initialize db by CSV and after run Elasticsearch returns []

I have a problem with searching by Elasticsearch. I use JHipser generator v.3.4.0 and I initialize my H2 database by *.csv files. Next I try search something, Elasticsearch always returns [] unless I add some object manually then I get only this one object. Do you have any ideas how to fix it?
Ok. I used jhipster-elasticsearch-reindexer and did POST form swagger-ui and now all objects can be reached by elasticsearch.
Edit:
I automatized Elasticsearch Reindexing. It invokes after start application. If you want to do it, follow the steps below.
Steps:
1. Add to your JHipster project Elasticsearch Reindexer from: https://github.com/geraldhumphries/generator-jhipster-elasticsearch-reindexer
2. Reindex elasticsearch on start by adding class:
#Component
public class ElasticsearchReindexOnStart implements ApplicationListener<ContextRefreshedEvent> {
private final ElasticsearchIndexService elasticsearchIndexService;
#Inject
public ElasticsearchReindexOnStart(ElasticsearchIndexService elasticsearchIndexService) {
this.elasticsearchIndexService = elasticsearchIndexService;
}
#Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
elasticsearchIndexService.reindexAll();
}
}
After that, restart your application and now it should works without doing POST from swagger-ui.

Customizing Yarn container

I'm testing spring-yarn integration API and I'm little confused about what is the best practice of Yarn container customization in terms of:
1) If I want to use spring-boot-yarn combo, what is the correct way of telling the spring boot to pick up my implementation of yarn container instead of DefaultYarnContainer...The only way I figured out was via ImportResource annotation at container project class containing main method, which was pointing to spring application xml with declaration:
<yarn:container container class="myhadoop.yarn.container.custom.MyContainerImplementation"/>
Component scan doesn't work at all...Spring boot was still using DefaultYarnContainer...
2) If I understand Yarn architecture correctly then application master is responsible for launching the container. But If I change DefaultYarnContainer for my implementation then I need to start container manually via run method, nothing was starting it, please what is the correct way?
Thanks a lot in advance for help
If boot is doing auto-configuration for yarn container, there are few ways to define the actual container which defaults to DefaultYarnContainer.
Logic of this can be found from here https://github.com/spring-projects/spring-hadoop/blob/master/spring-yarn/spring-yarn-boot/src/main/java/org/springframework/yarn/boot/YarnContainerAutoConfiguration.java#L107
Use spring.yarn.container.containerClass=foo.jee.MyContainer in yml
Create class as bean with name yarnContainerClass
Create your container impl as bean with name yarnContainerRef
Create bean as name customContainerClass which would be a class as string
Janne, thanks a lot! This way is far more elegant and it works...Here is what I did:
#EnableAutoConfiguration
#Configuration
#ComponentScan
public class ContainerApplication {
#Autowired
private MyContainerImplementation myContainerImplementation;
#Bean(name="yarnContainerClass")
public Class<? extends YarnContainer> getYarnContainerClass() {
return MyContainerImplementation.class;
}
#Bean(name="yarnContainerRef")
public MyContainerImplementation getYarnContainerRef() {
return myContainerImplementation;
}
#Bean(name="customContainerClass")
public String getCustomContainerClass() {
return "myhadoop.yarn.container.custom.MyContainerImplementation";
}
public static void main(String[] args) {
SpringApplication.run(ContainerApplication.class, args);
}
}
I added MyContainerImplementation into yml as you pointed and my container implementation was started by application master without me running the run method manually, because I see the following lines in the hadoop logs:
LifecycleObjectSupport:started
myhadoop.yarn.container.custom.MyContainerImplementation#5e2cd950
.
.
LifecycleObjectSupport: stopped
myhadoop.yarn.container.custom.MyContainerImplementation#5e2cd950
Anyway, I have additional question. I wanted to test low-level yarn things like ContainerStateListener and YarnPublisher, but they're not called at all..:-( Here is my test customized container:
#Component
public class MyContainerImplementation extends AbstractYarnContainer {
private static final Log log = LogFactory.getLog(MyContainerImplementation.class);
public MyContainerImplementation() {
super();
log.info("...Initializing yarn MyContainerImplementation....");
this.setYarnEventPublisher(new DefaultYarnEventPublisher() {
#Override
public void publishContainerAllocated(Object source, Container container) {
super.publishContainerAllocated(source, container);
log.info("Yarn container allocated: "+container.getResource().getMemory());
}
});
this.addContainerStateListener(new ContainerStateListener() {
#Override
public void state(ContainerState state, Object exit) {
switch(state) {
case COMPLETED: {
log.info("...Container started successfully!...");
break;
}
case FAILED: {
log.info("...Starting of container failed!...");
break;
}
default: {
log.info("Unexpected container state...exiting!...");
}
}
}
});
}
public void runInternal() {
log.info("...Running internal method...");
}
}
Do I need to add additional configuration to make ContainerStateListener and YarnPublisher to work?
You don't need to implement all beans for container, just one is
enough.
You're right. I didn't notice of the following method in SpringYarnConfig:
#Override
public void configure(YarnContainerConfigurer container) throws Exception {
if (StringUtils.hasText(sycp.getContainerClass())) {
container
.containerClass(sycp.getContainerClass());
} else if (yarnContainerClass != null){
container
.containerClass(yarnContainerClass);
} else if (yarnContainerRef != null) {
if (yarnContainerRef instanceof YarnContainer) {
container
.containerRef((YarnContainer) yarnContainerRef);
}
} else if (StringUtils.hasText(containerClass)) {
container.containerClass(containerClass);
}
}
where it's clear that one is really enough...:)
Use of event publisher and state listener are really meant as building
blocks what you'd need to call yourself.
Yes, I see that DefaultYarnContainer is handling notifyXXXX methods(fires up container state changes) calling by himself...Alright, I will definitelly play with it more.
Janne, thanks a lot for help. You provided perfect closer insight into Spring-Yarn.