I am using aws-cdk for creating the stack of a new app. We have existing resources deployed with Cloudformation, such as route tables with our VPC peerings and other.
When i create a Subnet with aws-cdk, it automatically creates a route table.
However, i don't need this route table. I use another, already created route table. How can i remove the default routetable ?
I can i could use CfnSubnet instead of Subnet, but I was wondering if there is another solution.
Subnet Subnet = new Subnet(this, "Subnet", SubnetProps.builder()
.withVpcId(vpc.getVpcId())
.withAvailabilityZone("eu-west-1b")
.withCidrBlock(String.format("10.%d.43.128/25", environmentId))
.build());
CfnSubnetRouteTableAssociation routeTableAssociation = (CfnSubnetRouteTableAssociation) subnet.getNode().tryFindChild("RouteTableAssociation");
routeTableAssociation.setRouteTableId(Fn.importValue(String.format("%s-nat-nat000", environment)));
CfnRouteTable cfnRouteTable = (CfnRouteTable) subnet.getNode().tryFindChild("RouteTable");
I think the solution you proposed is the best way to achieve that.
Related
I am asking this for local cluster.
Here is the code for getting the address and the name of the worker:
def f():
worker = get_worker().name
return worker
client.run(f)
Output:
{'tcp://127.0.0.1:58709': 0,
'tcp://127.0.0.1:58710': 2,
'tcp://127.0.0.1:58711': 1}
It is in the dictionary. The key is the address and the value is the name of the worker. is there any way to assign the worker's name while creating the client? or any way around.
just changing the dictionary value doesn't change the original of the worker.
My motivation behind this:
*My goal is to create a worker and assign the preprocessing task to that. After the create two models let's say logistic reg and random forest classifier.
and Now I want to scale up the worker using the scale method. and assign the model training for two models on two new workers.
But the thing is how will I identify which worker is the new worker? Because the worker name is like worker_0, worker_1, worker_2. Is the new worker which is created either worker_0 or worker_1? How do identify the new worker name?
I do believe that new worker names are in an incremental fashion.
But I need proof to validate my reason. That's why I thought It better to change the name. So that I can keep track of the worker more easily.*
Reference for the original question: How to get the worker name in dask cluster?
I'm afraid the current implementation of LocalCluster does not allow you to set the name via the constructor. You could propose a change to the codebase via a PR.
It raises the question, what do you wish to achieve with the names? You already have both a unique sequence number (the current .name) and unique UUID-based ID for every worker, as well as the workers' unique TCP addresses.
Finally - and this is untested - you could plausibly use client.run together with get_worker() to set the .name attribute dynamically at runtime, should you wish. The following would set the name attribute for the specific worker (as a TCP address) given in the workers= list.
def set_name(name):
get_worker().name = name
client.run(set_name, "name1", workers=[..])
-EDIT-
After providing motivation, I believe this question is not actually asking what you want - maybe make a new a new question. Perhaps clinet.who_has is what you want, but your workflow isn't clear to me.
I have an application that has multiple controllers that those controllers have within them 2 routes #Controller(['1/:someParam', '/2/:someParam']) but when I create swagger it shows both of them within the same group, what I need is to be able to group those as well.
Is there any possible way to create such a thing?
You can use ApiTags.
#ApiTags('firsturl', 'secondurl')
ApiTags accept string array as parameter.
How do a rename a domain class while reverse engineering or after reverse engineering.
i generated class using reverse engineering in Groovy and Grails.
the domain class name was AgentTable. I want to rename it as Agent. When i renamed the domain class using IntelliJ (right click - refactor - rename), it renamed the AgentTable to Agent whereever it was used. but when i start the server (run the app), giving error
"nested exception is org.hibernate.HibernateException: Missing table: agent"
I have to do this for few domain class. is it anyway i can give an alternative name while reverse engineering the domain classes.
or after domain class was created how do i rename it without this error.
Look into your database the name of the table it created for the agent. Once you know the name of the table add the following in your new domain
static mapping = {
table "table-name-here"
}
While it works I would not recommend #elixir 's approach.
In my opinion the mapping is not supposed to be used for renames. This is also how I understand the official documentation.
In the example they use it to map Person onto the 'people' table, not because of a rename but because of a semantic reason. Tables are typically named after the plural form. Here is a nice answer on another question regarding this. In the project I am working on the domain object 'User' is mapped to the table 'users'. You can not use the table name 'user' as it is an SQL statement.
Assumptions and clarifications:
In my experience Grails maps the domain name to the table name after these rules (example domain name 'MyExampleDomain':
separate the domain name by capital letters (My Example Domain)
lower case all (my example domain)
replace spaces with underlines (my_example_domain)
Following this your Domain Class 'AgentTable' has a table 'agent_table' in your respective database. After your rename Grails even tells you what it wants:
nested exception is org.hibernate.HibernateException: Missing table: agent
It wants to look up values in a table called 'agent' but it can not find it. The refactor function of IntelliJ does not rename the functions, so it will miss out on the database.
Luckily we know exactly what values it wants - the values previously found in 'agent_table'.
So why create this confusion with remapping domains and table names when we could just rename the table and be done with it?
The solution:
Execute an SQL script like this on your database:
ALTER TABLE <old_domain_name> RENAME TO <new_domain_name>;
The names are of course in their "table-form".
This simply renames your table to match the expected format in Grails. When restarting everything should be fine.
However you do not need to use rename. You could also create a whole new table, build it the way the domain objects wants it to be and then migrate the data. See section 'Problems with this approach' for information on when to use what.
Problems with this approach:
As always, tinkering with information a program depends on (and even generated itself) will often have some dire consequences if you aren't careful.
For example we have to pay attention to keys. If your domain object has a relation to other objects it will hold them in the table via foreign keys. Depending on how you chose to migrate the information in the table you might have deleted these foreign keys connections. You will have to add them via a separate SQL statement. When you choose to recreate the table this will happen for sure. Renaming it should keep the keys.
Another one are column names. If you choose to rename attributes you will also have to rename the columns via SQL. You will also have to remember the foreign keys other tables might have on the table you are renaming. RENAME did this automatically for me, but you should double check.
Why you should still stick with this approach:
Remapping domain objects to the tables with old names is bound to create code smell and confusion. Do you really want to remember these mappings in your head? And more importantly: do you really expect other people to have to work with this?
The best case is if people can't even tell if this object has ever had a different name and changing the database is the best way I know to achieve this.
I'm working on a Web API with MVC4, and I'd like to make it backwards-compatible, as I don't control when the clients are updated.
In order to do that, I'm going to create controllers on different namespaces, something like MyApp.Controllers.v1_0.AccountsController and MyApp.Controllers.v1_1.AccountsController
Obviously, when I create both of them and try to access to an action, I get "Multiple types were found that match the controller named 'Accounts'"
Then, what I tried to do is writing my own IHttpControllerActivator, so that when Create is invoked, it returns one of them... but that doesn't work b/c it never gets hit, which makes sense as Create receives an System.Web.Http.Controllers.HttpControllerDescriptor that includes information about the controller it's about to use.
Also, I can't just name the controllers different (Accounts1_0Controller, Accounts1_1Controller), as when the activators returns Accounts1_0Controller, it says that its name is not "Accounts"... it probably gets its name as Accounts1_0.
Do you see any way of either:
Set the namespace from the url? so that I have the url /v1_0/SomeAction or /v1_1/SomeAction and it searches the controller on the appropriate namespace
Having multiple controllers with the same MVC name but different class name?
Hope the issue is clear enough.
Thanks!
Fixed it implementing my own IHttpControllerSelector. It's great how Microsoft made MVC4 open source, made it almost painlessly looking at their System.Web.Http.Dispatcher.DefaultHttpControllerSelector.
I have a following domains
User (in database called usermanagement) and
Account (in another database xyz)
Its an old system so i cannot really change the architecture of the system. I have been assigned task to implement a system that a certain users can only access certain accounts. This is a classic case of many-to-many relationship but the problem lies in the fact that these two domains are in two different databases. I googled if that was possible but i realized that it was not possible. So I now am thinking of creating a custom join table to store info on which user are allowed access to which accounts. The table can have two columns 'accountId' and 'userId'. So for this, do i have to create a new domain in grails or is there any cleaver way of doing this ?
Thanks in advance.
If you create joinTable in which DB you are going to create it and how you are going handle updates in main (Account,User) tables and ceep your join table up2date ?
I think (for this case) you don't need join table, you need handle business logic in application level.
You cane have 2 Domain classes each one pointed to different dataSource(DataBase).
http://grails.org/doc/latest/guide/conf.html#multipleDatasources
As I searched for solution of this, I did not find any sustainable solutions. I eventually narrowed down the probable solutions to two:
1. Create a domain table (only) using sql, some sort of patch and use hard-coded queries in grails to write and access data to and from the table.
2. Create a domain class like AccountUser having properties clientId and userId
I choose the 2nd option, I wrote some additional methods and created a service to return user and client instance and I am done ! Anyways, thanks guys.
If the databases are "visible" to each other (on the same server or there is a db link between them), you should be able to map the domain classes using the fully qualified table names ('schema.tablename') in the mapping closure.
psuedocode:
class User {
static mapping = {
table "usermanagement.user"
}
static hasMany = [Account:accounts]
}
class Account {
static mapping = {
table "xyz.account"
}
}
http://grails.org/doc/latest/guide/GORM.html#tableAndColumnNames