Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODENVY-957 Implement resources redistribution between suborganizations #1141

Merged
merged 1 commit into from
Dec 12, 2016

Conversation

sleshchenko
Copy link
Contributor

@sleshchenko sleshchenko commented Nov 14, 2016

What does this PR do?

Added ability to redistribute resources between suborganizations.

Introduced new state for account's resources, it's called reserved resources. It means that account's license has resources but it can't use it for consumtion by workpace starting, creation etc.

Implemented new organization resources API that allows to define resources that should be provided for usage by suborganization from its parent organization. Only users who have manageResources permissions can grant suborganization to use parent organization's resources. Resources become unavailable for his parent organization when user allows suborganization to use them, so they become reserved resources. By default all suborganizations don't have any resources limit and it means that they are not able to use resources of their parent organizations.

What issues does this PR fix or reference?

#957

New Behavior

Organization can provide own resources to usage by their suborganizations.

Tests written?

Yes

Docs requirements?

Include the content for all the docs changes required.

  1. API changes
  2. User docs changes

@sleshchenko
Copy link
Contributor Author

sleshchenko commented Nov 15, 2016

@skabashnyuk @akorneta @evoevodin @mshaposhnik Please take a look my changes

@sleshchenko sleshchenko force-pushed the CODENVY-957 branch 5 times, most recently from 98619bb to fff6a09 Compare November 18, 2016 10:40
@sleshchenko
Copy link
Contributor Author

These changes should be merged with changes for #1198

@sleshchenko sleshchenko force-pushed the CODENVY-957 branch 2 times, most recently from 9cafe1d to 04dfa49 Compare November 24, 2016 16:14
* @throws ServerException
* when any other error occurs
*/
public void setResourcesLimit(OrganizationResourcesLimit resourcesLimit) throws NotFoundException,
Copy link
Contributor

@voievodin voievodin Nov 25, 2016

Choose a reason for hiding this comment

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

The name of the method looks inconsistent with get, i mean it's should be either

setResourcesLimit 
getResourcesLimit

or(i like this one)

setLimit
getLimit

or even

set
get

but not

setResourcesLimit
get

if (existed != null) {
try {
final Resource deducted = resourceAggregator.deduct(existed, newResource);
// existed resource amount is more than new one
Copy link
Contributor

Choose a reason for hiding this comment

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

is greater than

case RESET_DISTRIBUTED_RESOURCES:
//we should check permissions on parent organization level
String suborganizationId = (String)arguments[0];
final String parentId = organizationManager.getById(suborganizationId).getParent();
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't see any purpose from having 2 more variables.
e.g the following code looks also ok to me:

organizationId = organizationManager.getById((String)arguments[0]).getParent();
if (organizationid == null) {
    return;
}
break;

}


if (!currentSubject.hasPermission(DOMAIN_ID, organizationId, OrganizationDomain.MANAGE_RESOURCES)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use class name along with DOMAIN_ID, from the code it's not clear what domain is identified with this id.
Moreover you use SystemDomain.DOMAIN_ID above, does it make any sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also you use MANAGE_ORGANIZATION_ACTION as static import

import static com.codenvy.organization.api.permissions.OrganizationPermissionsFilter.MANAGE_ORGANIZATIONS_ACTION;

but you don't do it with OrganizationDomain.MANAGE_RESOURCES is there any regularity i don't see?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. I removed static imports for domains' identifiers and action to make more clear their locations

*/
@Singleton
public class OrganizationResourceLockKeyProvider implements ResourceLockKeyProvider {
private OrganizationManager organizationManager;
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like final is missing

}
return organization.getId();
} catch (NotFoundException e) {
throw new ServerException(format("Organization with id '%s' was not found during resources locking.",
Copy link
Contributor

@voievodin voievodin Nov 30, 2016

Choose a reason for hiding this comment

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

during resources locking

looks like you just trying to get a lock key, so i think the message should be a bit different

}

@POST
@Path("{suborganizationId}")
Copy link
Contributor

Choose a reason for hiding this comment

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

reset method path starts with / while this path doesn't, i find it a bit inconsistent don't you?

@ApiOperation(value = "Distribute resources for suborganization.",
notes = "Distributed resources is unavailable for usage by parent organization." +
"It should reset resources distribution before consuming.",
response = OrganizationDistributedResourcesDto.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

lie, this method returns nothing

@Path("/{organizationId}")
@ApiOperation(value = "Reset resources distribution.",
notes = "After distribution resetting suborganization won't be able to use parent resources.")
@ApiResponses({@ApiResponse(code = 201, message = "Resources distribution successfully reset"),
Copy link
Contributor

Choose a reason for hiding this comment

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

why 201, it's 204 i think

}

/**
* TODO Revise doc
Copy link
Contributor

Choose a reason for hiding this comment

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

do it! 🚀

Copy link
Contributor

@voievodin voievodin left a comment

Choose a reason for hiding this comment

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

It seems that you did a pretty big amount of work, good job! Some of the futures are context specific so it's hard to review all of them, the code in general looks okay to me.

-- from Codenvy S.A..
--

-- Organization distributed resources ))---------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

delete the brackets please

*/
public interface OrganizationDistributedResourcesDao {
/**
* Stores distributed resources for suborganization.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it will be helpful to describe here how to store resources when there are already exist resources for the organization.

@sleshchenko sleshchenko changed the title [WIP] CODENVY-957 Implement resources redistribution between suborganizations CODENVY-957 Implement resources redistribution between suborganizations Dec 1, 2016
@sleshchenko sleshchenko force-pushed the CODENVY-957 branch 2 times, most recently from f5d23e2 to 9ef1706 Compare December 8, 2016 07:58
@sleshchenko sleshchenko force-pushed the CODENVY-957 branch 5 times, most recently from f3f9ac1 to 461842f Compare December 8, 2016 09:49
@ashumilova ashumilova added this to the 5.0.0-M9 milestone Dec 8, 2016
@musienko-maxim
Copy link
Contributor

After running the selenium tests new regression has not been found

@sleshchenko sleshchenko merged commit 6393a43 into codenvy:master Dec 12, 2016
@sleshchenko sleshchenko deleted the CODENVY-957 branch December 12, 2016 11:09
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.

6 participants