Skip to content

Issue #OS-131 Shard advisory for serialnum property#3

Open
pc0202 wants to merge 19 commits into
release-2.0.0from
OS-131
Open

Issue #OS-131 Shard advisory for serialnum property#3
pc0202 wants to merge 19 commits into
release-2.0.0from
OS-131

Conversation

@pc0202
Copy link
Copy Markdown
Owner

@pc0202 pc0202 commented Dec 7, 2018

Indroduced Shard advisor.
Added interface IShardAdvisory. Single sample impl for serial number property.
ShardAdvisor for registering the impl with property, this suppose to get pre loaded.
Shard factory intiatiate a connection with help of ShardAdvisor.
Introduced ShardManager to activate a Shard instance
TODO:

  1. Test files ignored as need DatabaseProvider autowired. Needs to autowire the ShardAdvisor and get Database provider by DBShard.

import java.util.Map;


public class AdvisoryLoader {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name sounds generic. Let us call it ShardAdvisor and think of making the getShard(String property) as a static method. We expect this class to be initiated once.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named it as ShardAdvisorLoader:getShardAdvisory(String property)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getShardAdvisor() please...

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, done.


import io.opensaber.registry.model.DBConnectionInfo;

public interface IShardAdvisory {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IShardAdvisor that has a method getShard()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IShardAdvisor has: DBConnectionInfo getShard(String attribute)
I hope this what you are expecting?

}

@Override
public DBConnectionInfo connectionInfo(String subject) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename subject as serialNumber to make it clear.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Autowired
AdvisoryLoader advisoryLoader;

public DatabaseProvider getInstance(String property, String value) throws IOException{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the DBShard just manages the connection. It does not need to know the attribute, value details. Given a shardId or connectionInfo, it merely gives initializes a provider. All this must either go to a separate class or this class be re-invented.
Treat DBShard as one that can just give a 'graph' instance, when you supply a connectionInfo.
Treat Advisor as one that merely advises the connectionInfo to be used for a given attribute value.
Treat X (to be invented) as one that can handle both the above classes and give you 'graph' instance.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown

@indrajra indrajra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good going, few minor stuff. Fix them and we will merge.

public DBConnectionInfo getShard(Object serialNumber) {

DBConnectionInfo connectionInfo = null;
if (serialNumber != null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this is too complex for an example. Why is a serialNumber not an integer?
if it is not because of schema definitions, lets correct it.
This must be a simple switch case, slNum % 2 == 0 implies it is even and so shard X; otherwise shard Y.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes right kept it for some default shards. Done now.


private Map<String,IShardAdvisor> advisors = new HashMap<String,IShardAdvisor>();

public void registerAdvisor(String property, IShardAdvisor shardAdvisory){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put comments to this one please.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKay. Done

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { RegistryDaoImpl.class, Environment.class, ObjectMapper.class, GenericConfiguration.class,
EncryptionServiceImpl.class, AuditRecordReader.class })
EncryptionServiceImpl.class })
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo this and the Autowired commented out few lines below.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

@Test
@Ignore @Test
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these must haves? otherwise please revert these changes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants